jQuery and UpdatePanels

While using a jQuery plugin to round corners, they started to disappear inside UpdatePanel’s after a partial post back. I found someone else on StackOverflow had the same problem. Luckily, the solution was right there as well.

$(document).ready(function() {
    doReady();

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function(s, e) {
        doReady();
    });
});

function doReady() {
    $('.roundedCorners').corners();
}

I’m interested in trying the livequery jQuery plugin, but will go with this for now.

6 Comments so far

  1. Alberto B on February 16th, 2009

    This is the best. Thanks. I struggled to find a solution for more than a day.

  2. mark on February 16th, 2009

    @Alberto, I’m glad it helped. Also, look at event delegation and the new live method for other ways to assign event handlers to controls inside update panels.

  3. Bill Sambrone on May 23rd, 2009

    I’ve been google searching for over a week now, and I was about ready to bash my face into a keyboard until I disfigured myself for eternity – because I couldn’t figure out how to make my jquery goodness come back after a partial postback. I basically cut ‘n pasted the code above – all is solved!

  4. mark on May 24th, 2009

    @Bill I’m glad it was useful. There is another event that will fire both on page load and after partial postback, but the name of it escapes me. I prefer to keep things separate since most of the time there are things that do not happen on both.

    Keep in mind if you are applying style, or adding event handlers, it code not inside the partial post back might get them twice.

  5. Leona on January 23rd, 2010

    Hi, instead of calling a jquery function, I have a bunch of js and css files I need to re-register due to partial postback with updatepanel. How would I do this? Thank you.

  6. mark on January 25th, 2010

    @Leona I’m not sure how to re-register the CSS and JavaScript, but I would look at dropping the SCRIPT and LINK tags and adding them back. That would be my first try.

Leave a Reply