0

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?

3
  • Have you tried jQuery live method. Commented Feb 22, 2010 at 12:58
  • I have tried it but it didn't work for me. I hope I haven't misused it. I'm going to try the JSON AJAX approach instead of Update pannels according to this link: encosia.com/2007/07/11/… Commented Feb 22, 2010 at 13:07
  • Without any examples of what you've tried, it's pretty hard to help you. Commented Feb 22, 2010 at 13:45

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

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.
Thanks this helped me re-style a table using jquery which was updated (recreated) using asp.net ajax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.