Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
Have you tried jQuery live method. – rahul Feb 22 '10 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/… – Desecho Feb 22 '10 at 13:07
Without any examples of what you've tried, it's pretty hard to help you. – Pointy Feb 22 '10 at 13:45

1 Answer

up vote 1 down vote accepted

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>
share|improve this answer
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 Feb 25 '10 at 13:11
Thanks this helped me re-style a table using jquery which was updated (recreated) using asp.net ajax – tomfumb Nov 28 '11 at 19:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.