Monday, March 26, 2012

Call javascript after UpdatePanel updates

Hi,

Is it possible to call a javascript function after the update panel finishes updating? For example - I click on a product which populates a table inside an update panel, when this update is complete I would like to move the div containing the product data to the point where the user clicks. My problem is how to call the javascript that makes this happen.

Thanks for any and all advice / code / links.

Hello,

you need to create a javascript function and bind that to the pageloaded event of the pagerequestmanager class. Here's how it might look:

var prm = Sys.WebForms.PageRequestManager.getInstance();prm.add_pageLoaded( function() { // Your function body comes here});

The pagerequestmanager is responsible for handling the AJAX calls. It has several events that you can handle.

Good luck!


hello.
well, in this case, I'd use the endrequest event of the pagerequest manager since it is called only when the?partial?postback?ends?(and?it's?also?called?when?you?get?an?error?during?a?partila?postback).?the?code?is?the?same?as?the?previous?poster?has?shown;?the?difference is?that?yo?use?the?add_endRequest?method?instead?of?calling?the?add_pageLoad?method.
Correct, my example with the pageloaded will also execute the first time the page loads. That might not be what you need, so go with endrequest like the previous poster said.

You probably want to subscribe to the pageLoaded event so that you can access the panelsUpdated property.

http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageLoadedEventArgsClass/PageLoadedEventArgsPanelsUpdatedProperty.aspx

Example:

http://ajax.asp.net/docs/ViewSample.aspx?sref=Sys.WebForms.PageRequestManager.pageLoaded

No comments:

Post a Comment