Tuesday, May 19, 2009

Access MasterPage ScriptManager from a Content Page

You probably know that each ASP.NET Ajax page MUST have ONLY ONE ScriptManager control.
No more, no less.

If you try to add more than one ScriptManager to ASP.NET page you will receive error:
"Only one instance of a ScriptManager can be added to the page."

Because of this, its common (and recommended) practice to use this approach:
Create MasterPage, and place ScriptManager control on it and then use this instance on each of ContentPages.

here is the code that you can place on your ContentPage to retrieve an instance of ScriptManager from MasterPage:


ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);

No comments: