The Safe Script Manager

The ASP.NET script manager is a component of the .NET Framework that manages ASP.NET AJAX script libraries and script files, partial-page rendering, and client proxy class generation for Web and application services. For more information about the ScriptManager control, see ScriptManager Class and ScriptManager Control Overview on MSDN. For information about the AJAX script libraries and script files, see Adding AJAX and Client Capabilities Roadmap on MSDN.

The script manager has a requirement that only one instance of the ScriptManager control can be added to a Web page. If you add two script managers, the second script manager throws an exception.

There are two ways to enforce this requirement:

  • Ensure that the ScriptManager control is present on each page by adding it to all master pages. This is a good approach if almost all pages use AJAX functionality. However, adding the ScriptManager control to each page increases overhead because it adds the AJAX script references to the page.
  • Check to see if a ScriptManager control is already present before adding a new ScriptManager control. This must be done in code, not in the ASPX or ASCX markup. Developers must remember to perform this check each time they want to use the control.

The SharePoint Guidance Library's SafeScriptManager class solves this issue. The SafeScriptManager class is an ASP.NET custom control that loads the .NET Framework's ScriptManager control if it is not already present on the current Web page. The safe script manager is a reusable component that you can include in your own SharePoint applications. It also includes SharePoint-specific support for AJAX update panels.

This section includes the following topics:

Home page on MSDN | Community site