ScriptManager Control Overview
The ScriptManager control manages client script for AJAX-enabled ASP.NET Web pages. By default, the ScriptManager control registers the script for the Microsoft Ajax Library with the page. This enables client script to use the type system extensions and to support features such as partial-page rendering and Web-service calls.
This topic contains the following sections:
You must use a ScriptManager control on a page to enable the following Microsoft Ajax features of ASP.NET:
Client-script functionality of the Microsoft Ajax Library, and any custom script that you want to send to the browser. For more information, see Creating Custom Client Script by Using the Microsoft Ajax Library.
Partial-page rendering, which enables regions on the page to be independently refreshed without a postback. The ASP.NET UpdatePanel, UpdateProgress, and Timer controls require a ScriptManager control in order to support partial-page rendering.
When a page contains one or more UpdatePanel controls, the ScriptManager control manages partial-page rendering in the browser. The control interacts with the page life cycle to update the parts of the page that are inside UpdatePanel controls. For more information, see Partial-Page Rendering Overview.
The EnablePartialRendering property of the ScriptManager control determines whether a page participates in partial-page updates. By default, the EnablePartialRendering property is true. Therefore, by default partial-page rendering is enabled when you add a ScriptManager control to the page. For information about how to use the UpdatePanel control with the ScriptManager control, see Introduction to the UpdatePanel Control and Creating a Simple ASP.NET Page with Multiple UpdatePanel Controls.
Handling Partial-page Rendering Errors
During partial-page rendering, you can handle errors by doing the following:
Set the AllowCustomErrorsRedirect property. This determines how the custom error section of the Web.config file is used when an error occurs during an asynchronous postback.
Set the AsyncPostBackErrorMessage property, which is the error message that is sent to the browser.
Using Type System Extensions
Registering Custom Script
Use the ScriptManager control to manage resources that you have created for controls that participate in partial-page updates. Resources include scripts, styles, hidden fields, and arrays. The Scripts collection of the ScriptManager control contains a ScriptReference object for each script that is available to the browser. You can specify the scripts declaratively or programmatically.
The ScriptManager control also exposes registration methods that you can use to manage client script and hidden fields programmatically. When you are registering script or hidden fields that support partial-page updates, you must call registration methods of the ScriptManager control. (To register scripts that are not needed for partial-page updates, you use methods of the ClientScriptManager class.)
Any scripts on the page that are registered by using the ScriptManager control and all event-handling script must be inside the form element on the page. Otherwise the script will not be registered or executed.
For a list of the ClientScriptManager controls registration methods, see Creating Custom Client Script by Using the Microsoft Ajax Library and the ClientScriptManager class overview.
Registering Web Services
To register a Web service that you want to call from an AJAX-enabled ASP.NET page, you register the Web service by adding it to the ScriptManager control's Services collection. The Microsoft Ajax framework generates a client proxy object for each ServiceReference object in the Services collection. The proxy classes and their strongly typed members simplify using Web services from client script.
Using Authentication, Profile, and Role Services from Client Script
The ScriptManagerProxy Class
Only one instance of the ScriptManager control can be added to the page. The page can include the control directly, or indirectly inside a nested component such as a user control, content page for a master page, or nested master page. If a page already contains a ScriptManager control, but a nested or parent component needs additional features of the ScriptManager control, the component can include a ScriptManagerProxy control. For example, the ScriptManagerProxy control enables you to add scripts and services that are specific to nested components.
A server control that makes script resources available to the browser, which includes the Microsoft Ajax Library and the functionality that enables partial-page rendering.
A server control that enables nested components to add script and service references if the page already contains a ScriptManager control.