开发者

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 开发者_C百科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?


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:

  • Ajax Page Life Cycle Event Handler Arguments
  • MSDN - Sys.WebForms.PageRequestManager pageLoaded Event
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜