UpdatePanelExtender Upgrade

In Updating an UpdatePanel in the Client side, I described how I was able to update an UpdatePanel from the client side. The solution was pretty simple: Create an extender which adds an hidden button to the update panel, and performs a click on it when the update() method is called from the JavaScript.

Recently I saw a new Webcast in the Asp.Net Ajax How Do I series which explains how to do this with and without the button.

In short, the solution requires a call to a private method in the PageRequestManager which performs a post back:

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack(updatePanelClientID,”);

I decided to upgrade the extender, which now calls this method instead of adding a button and clicking on it. It makes the server and client code of the extender cleaner, and more simple.

Also I have fixed the issue of the OnUpdated event, which is now working perfectly: It is triggered when the update() method in the client is called. I caused the event to trigger by using properties from the ScriptManager:

ScriptManager currentScriptManager = ScriptManager.GetCurrent(Page);

if ((currentScriptManager.IsInAsyncPostBack) &&
	(currentScriptManager.AsyncPostBackSourceElementID == TargetUpdatePanel.ID))
{
	OnUpdated(new UpdatedEventArgs());
}   

I simply check if the post back is asynchronous and was caused by the update panel (the id I used when I called the _doPostBack method in the client).

Feel free to download and use my brand new UpdatePanelExtender!

I will be glad to read your comments,suggestions, bugs, etc...

Have a great weekend