[resolved] Script Manager in ASP.net master page issue

If you are using a script manager in your master page in order to share it with all your pages instead of adding a script manager to each page , you need to follow the following steps in order to avoid any further problems:

1- Make sure you have added the script manager tag after opening of Form tag.

2- To access the master page script manager you may use one of those ways :

  • Create a public property in your master page which will return the current instance of script manager and use it in your content page.

In your master page .cs file

public ScriptManager rootScriptManager { 
get { return matserScriptManager; } 
}

In content page

//Sit1 is the master page class name
Site1 site1 = Master as Site1;
//check the script manager property
 if(site1.rootScriptManager.IsInAsyncPostBack)
   {
   //Do something             
   }
ScriptManager scriptManager = 
(ScriptManager)Master.FindControl("matserScriptManager");
if(scriptManager != null && scriptManager.IsInAsyncPostBack)
 {
  //Do something
  }
if(scriptManager != null && scriptManager.IsInAsyncPostBack)
     {
        //Do something
       }
  • Another way which is recommended
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
            if(scriptManager != null && scriptManager.IsInAsyncPostBack)
            {
                //Do something
            }
Hope it helps :)

1 Comment

  • Actually, MS supplies the ScriptManagerProxy control for this purpose. From the MSDN Library,

    "Enables nested components such as content pages and user controls to add script and service references to pages when a ScriptManager control is already defined in a parent element."

    and

    "A Web page can contain only one ScriptManager control, either directly on the page or indirectly inside a nested or parent component. The ScriptManagerProxy control lets you add scripts and services to content pages and to user controls if the master page or host page already contains a ScriptManager control.

    When you use the ScriptManagerProxy control, you can add to the script and service collections defined by the ScriptManager control. If you do not want to include specific scripts and services on every page that includes a particular ScriptManager control, you can remove them from the ScriptManager control. You can then add them to individual pages by using the ScriptManagerProxy control instead."

Comments have been disabled for this content.