views:

172

answers:

1

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?

A: 

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>
Mehdi Golchin
It is what I was looking for, but my jquery sorting still fails along with jquery validation. I probably need to work on that more thoroughly.
Desecho