简体   繁体   中英

How to call function in code-behind c# with javascript?

How to call function in code-behind in c# with javascript?

I have this code behind :

protected void btn_Click(object sender, EventArgs e)
{
    if (btn != null && btn.Checked)
    {
        Response.Redirect(string.Format("get.aspx?a={0}&b={1}", 
                                         a.SelectedValue, b.SelectedValue));
    }
}

And I have a Checkbox :

<asp:CheckBox ID="btn" runat="server" Checked="false" />

I am tryong to call that function btn_Click in javascript :

var btn = document.getElementById("btn");

if (btn.checked) {
    '<% = btn_Click() %>'
}

But not worked!!! Why? Thanks.

您可以执行此处说明的适当的ajax方法-> http://www.techillumination.in/2013/07/an-aspnet-way-to-call-server-side.html

you can do it like this using Jquery, This is not tested

var button = $("#btn");
$(button).trigger("click");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM