From inspiration to realization
1Feb/102

jQuery and UpdatePanels (Asp.Net)

Well, I love using jQuery.

I think this open-source js library is simply the best when you want to create a more rich user experience in your websites and applications.

Some will argue mootools is better but hey, this is a long and exausting battle, almost like the one between PHP and ASP.net

This post comes to explain the difficulties when using jQuery dom event like "click" and "change" with an update panel.

Just one thing before I start, this post assumes you know jQuery, it also assumes you know your way around .net and you also know what an UpdatePanel is.

So, let's begin

This is what our application looks like:

What do we have here?

We have an updatePanel containing a grid with data from the server and a client-side button.

This client-side button has an event attached to it with jQuery like so:
Now, let's explain what's happening.

When the updatePanel fires an update event, all of the content inside it will be replace, but, with replacing this content all of the DOM data attached to it will also be disposed.

So, when we try to click the button after an updatePanel update the event will not be fired. To avoid this, jQuery offers a "live" event So, we will use the code like this

This will solve the problem for you.

Questions, comments?

feel free

Avi Tzurel

My name is Avi Tzurel. I'm a professional web developer from Israel. I spend most of my day developing both web products and RIA applications as well as imparting my experience onto others. I speak, teach and write about my passions, and develop applications according to what I preach. I specialize in Flex, Adobe Air, HTML, XHTML, Javascript, jQuery and other Javascript libraries, on the server side I do .net along side with Ruby on Rails. You can connect with me on Twitter or email me through the contact page on this blog.

  • Share/Bookmark
Comments (2) Trackbacks (1)
  1. I have similar problem. I’m neewbie in Jquery and Javascript.
    My code is:

    $(document).ready(function () {
    $(“#btCerca”).button({
    icons: {
    primary: ‘ui-icon-search’
    }
    }).click(function () {
    document.getElementById(“”).click();
    return false;
    });

    How I need to modify my code to solve problem?

  2. I don’t understand what does that code supposed to be doing?
    especially the click part, what do you want to click when you do that?


Leave a comment