Call Javascript from codebehind asp.net

本文关键字:asp net codebehind from Javascript Call | 更新日期: 2023-09-27 18:16:04

我试图得到一个花哨的盒子打开一个div和gridview一旦gridview已经填充了数据。

我可以直接调用fancybox来打开fancybox,或者我可以在不显示fancybox的情况下填充girdview。

这是我的代码,只是填充girdview的时刻,因为这是我需要去的地方。

任何和所有的帮助感谢。

的方法
 Public Sub GetEmailContacts()
    Session("RoleCode") = 27
    Dim dt As DataTable
    Dim dtToBind As DataTable = New DataTable()
    dtToBind.Columns.Add("Contact Type", Type.GetType("System.String"))
    dtToBind.Columns.Add("First Name", Type.GetType("System.String"))
    dtToBind.Columns.Add("Last Name", Type.GetType("System.String"))
    dtToBind.Columns.Add("Email Address", Type.GetType("System.String"))

    dt = GetValues()
    For Each dr As DataRow In dt.Rows
        dtToBind.Rows.Add(dr(0).ToString(), dr(6).ToString(), dr(7).ToString(), dr(9).ToString())
    Next
    For Each dr As DataRow In dtToBind.Rows
        Dim toButtonField = New ButtonField() With {
            .ButtonType = ButtonType.Button,
            .Text = "To: ",
            .CommandName = "DoSomething"
        }

        Dim ccbuttonField = New ButtonField() With {
            .ButtonType = ButtonType.Button,
            .Text = "Cc: ",
            .CommandName = "DoSomething"
        }
        gvContactList.Columns.Add(toButtonField)
        gvContactList.Columns.Add(ccbuttonField)
        Exit For
    Next
    gvContactList.DataSource = dtToBind
    gvContactList.DataBind()
    bttnTo.Attributes.Add("OnClientClick", "#emailAddress")
End Sub

The LinkButton:

<asp:LinkButton runat="server" cssclass="fancybox" ID="bttnTo" OnClick="getEmailContacts"><span style='font-size: 20px; color: darkgreen'><i id="toEmail" class="fa fa-users sameRow margin10"></i></span></asp:LinkButton>

这是JS文件中的内容

$(document).ready(function () {
$(".fancybox").fancybox({
    parent: "form:first" // jQuery selector
});

});

标准链接

<a href="#emailAddresses" class="fancybox"><span style='font-size: 20px; color: darkgreen'><i id="toEmail" class="fa fa-users sameRow margin10"></i></span></a>

如何最好地调用这个函数?

Call Javascript from codebehind asp.net

在这里更新你的javascript

$(document).ready(function () {
    fancybox = $(".fancybox").fancybox({
        parent: "form:first" // jQuery selector
    });
    if (gridLoaded) {
        fancybox.click();
    }
});

您必须在第一页加载时将gridLoaded设置为false,然后当您完成加载网格时将gridLoaded设置为true