简体   繁体   中英

How to add a javascript event handler using asp.net ajax

I am wondering how to add a javascript event handler using asp.net ajax. I need to add event handlers after ajax update because Jquery plugin to sort tables doesn't work and the onload method to display a screen keyboard does not trigger as well. Is there a way to do that? Maybe I need to switch to some other ajax library or/and try Asp.Net MVC to accomplish?

Your question is a little unclear. Anyway, if you are after to add an event handler to an element after partial update, check the following sample.

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </ContentTemplate>
</asp:UpdatePanel>

<script type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function() {
        if (prm.get_isInAsyncPostBack) {
            $addHandler($get("Button1"), "click", function() {
                alert("This is a test...");
            });
        }
    });
</script>

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