Friday, 17 April 2020

How to call JQuery function from C#?

Hi, you can try ClientScriptManager.RegisterStartupScript Method, for more information about this method, please refer to the following document:
I made an example, you can refer to it:
Default.aspx:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
    <script src="JScript1.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <div id="div1" style="display: none">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:TextBox ID="TextBox2"
                runat="server"></asp:TextBox>
        </div>
    </div>
    </form>
</body>
</html>
Default.aspx.cs:
protected void Button1_Click(object sender, EventArgs e)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "test", "lbviewmore_click()", true);
        }
JScript1.js:
function lbviewmore_click() {
    $('#div1').dialog({
        autoOpen: false,
        title: 'Basic Dialog'
    });
    $('#div1').dialog('open');
} 

No comments:

Post a Comment