views:

317

answers:

1

A control contains some HTML and some jQuery to handle a fancy tooltip to display when you click an image within a div.

The control is then used on several different pages, sometimes within an updatePanel, sometimes not.

I have the following code to handle loading the jQuery after a partial postback when the control is displayed within an update panel.

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

   function EndRequestHandler(sender, args) {
      $('img.ormdShipping').each(function(){
            $(this).qtip({

        // some qtip options go here
        })
      });
   }

Problem is, the jQuery doesn't load when the control is used anywhere other than an updatePanel. Do I need a second function that's triggered outside of the EndRequestHandler?

+2  A: 

Just call it once the page loads as well, you can do that by adding this at the end:

$(EndRequestHandler);

This will cause that code to run both when an UpdatePanel refreshes, and when the page first loads. When you pass in a function to the jQuery constructor, you're calling the jQuery(callback) version, if it's easier to think about, you're doing the short version of this:

$(document).ready(EndRequestHandler); //or..
$(document).ready(function() { EndRequestHandler(); });
Nick Craver
Thank you! This seemed to do the trick, exactly what I was looking for. =D
chromaloop

related questions