Mixing ASP.NET Ajax and jQuery

One of my clients has an application which makes extremely heavy use of UpdatePanels.  That’s my way of saying it was “architected” by idiots. It’s okay for me to say that, as they didn’t design it themselves – instead they paid a set of so called experts to do it for them. HINT: when you’re nesting UpdatePanels more than 3-4 levels deep, and using them in repeater templates then you’re doing it wrong.

A couple of changes they wanted made were going to be easier done using jQuery, so in it went, however it took a few more tweaks to get it working correctly due to the UpdatePanels.

The short summary is that you can get the two to play nicely together, depending on what you’re doing of course. In my case the physical location of the JavaScript seemed to make a difference, but the main change was using ASP.NET Ajax’s pageLoad() event to attach my jQuery event handlers instead of (document).ready(). I also found in one instance that I had to unbind all my events before binding them, to avoid duplicate event handlers being attached to a single element when the asynchronous postbacks occur.

Some links for anyone doing something similar:

Link: (document).ready() and pageLoad() are not the same!

Link: Simplify ASP.NET AJAX client-side initialization

Link: How to call client-side Javascript function after an UpdatePanel asychronous (Ajax) request is over

Link: UpdatePanel kills my jQuery

Tags: ,

Posted on Saturday, October 24, 2009 7:04 PM |

Like this? Share it!

No comments posted yet.

Post a comment
Please add 6 and 2 and type the answer here:
Remember me?
Ensure the word in this box says 'orange':