Josh Kodroff
Josh Kodroff

Reputation: 28121

How do I get the ID of the UpdatePanel(s) in ASP.NET AJAX that a response is destined for?

I'm trying to run some jQuery initialization code when new elements appear in the DOM as a result of an async request in an UpdatePanel. I can't seem to find the piece of data I want in the arguments to the endRequestHandler.

Anyone know where the data I'm looking for is located?

            function onEndRequest(sender, e) {
                // run some jQuery initialization code (e.g. .tabs()) 
               // here. but only on the affected updatepanel(s)
            }

            with (Sys.WebForms.PageRequestManager.getInstance()) {
                add_endRequest(onEndRequest);
            }

Alternatively, I could run my initialization code over the HTML in the response (if that's even possible). Any ideas?

Upvotes: 1

Views: 493

Answers (1)

cweston
cweston

Reputation: 11637

You can use the args.get_panelsUpdating(); within the pageLoaded handler to get a collection of update panels who's content has been refreshed.

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);

function pageLoaded(sender, args) {
   var updatedPanels = args.get_panelsUpdated();
   for (i=0; i < updatedPanels.length; i++) {            
       $(updatedPanels[i]).children('.tabContainer').tabs();
   }
}

References:

Upvotes: 1

Related Questions