Sunday, March 11, 2012

Getting the ID of the UpdatePanel that was updated in the most recent asynchronous postbac

In your example, sender._panelsToRefreshIDs is an array of UpdatePanel IDs being updated.


Hi i haven't really tried sender._panelsToRefreshIDs.

But i have used args.get_panelsUpdated()in my app. It works great.


Hi

I tried to use the sender_panelsToRefreshIDs as follows in the code, but it does not seem to work:

<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args)
{
var updatedPanels = sender._panelsToRefreshIDs;
for (i = 0; i < updatedPanels.length; i++)
{
if (updatedPanels[i] == "UpnlImages1")
{
var objDiv = document.getElementById("ctl00_InnerContentPlaceHolder_pnlImages1");
objDiv.scrollLeft = 0;
objDiv.scrollLeft = objDiv.scrollWidth;
}
}
}
</script>

I tried checking the ID of the UpdatePanel control (UpnlImages1 that is used in Visual Studio) as well as the ID that is generated in the browser (ctl00_InnerContentPlaceHolder_UpnlImages1) for the UpdatePanel of interest to me.

what am I doing wrong here. Thanks



I'd suggest either putting an alert(updatedPanels[i]) in your loop, or using FireBug to set a breakpoint at that position and inspect the value of the array.

This is an old, but still relevant post I made about using FireBug for that purpose:http://encosia.com/2007/03/06/debug-and-explore-aspnet-ajax-with-firebug/


I had placed the alert dialog earlier, but IE did not display it at all because of some unknown Javascript error on that page.

I tried it in Firefox and the array displayed the UpdatePanel's ID value as "ctl00$InnerContentPlaceHolder$UpnlImages1" instead of "ctl00_InnerContentPlaceHolder_UpnlImages1" (which is how you see it in browser's view source).

So i replaced the _ to $ in my if condition and it worked.

Thanks for all your help.


No problem. Glad you got it working.

No comments:

Post a Comment