The scriptmanager control manages client scripts for ASP. NET web pages that support Ajax. By default, the scriptmanager control registers the Microsoft Ajax library script to the page. This will enable client scripts to use the Type System Extension and support partial page rendering and web services to call such features.
The scriptmanager control must be used on the page to enable the following ASP. NET Ajax functions:
· The client Script Function of Microsoft Ajax library and any custom scripts to be sent to the browser.
· Partial pagination. You can refresh the area on the page without sending back. The ASP. NET updatepanel, updateprogress, and timer controls require the scriptmanager control to support partial page rendering.
· JavaScript proxy class of web services, allowing you to use client scripts to access the methods that are particularly marked in Web Services and ASP. NET pages. It exposes Web Services and page methods as strongly typed objects.
· JavaScript class, used to access ASP. NET authentication, configuration files, and role application services.
When a page contains one or more updatepanel controls, the scriptmanager control manages partial pagination in the browser. This control interacts with the page lifecycle to update the partial pages in the updatepanel control.
The enablepartialrendering attribute of the scriptmanager control determines whether a page is involved in partial page update. By default, the enablepartialrendering attribute is true. Therefore, by default, partial page rendering is enabled when the scriptmanager control is added to the page.
1. processing part page rendering error
During partial pagination, you can handle errors by performing the following operations:
· Set the allowcustomerrorsredirect attribute. When an error occurs during asynchronous sending back, this attribute determines how to use the custom error section of the web. config file.
· Process the asyncpostbackerror event of the scriptmanager control. This event is triggered when a page error occurs during asynchronous sending back.
· Set the asyncpostbackerrormessage attribute, which is an error message sent to the browser.
2. Type System Extension
Microsoft Ajax library can be used to add type system extensions to JavaScript to provide namespaces, inheritance, interfaces, enumerations, mappings, and helper functions for strings and arrays. These extensions provide functions similar to. NET Framework in client scripts. With these extensions, you can write Ajax-supported ASP. NET applications in a structured manner, which not only improves maintainability, but also makes it easier to add functions and hierarchical operations. Add the scriptmanager control to the ASP. NET webpage to automatically include type system extensions, allowing you to use the library in client scripts.
3. Register a Custom Script
You can use the scriptmanager control to manage the resources you have created for the Control Involved in partial page update. These resources include scripts, styles, hidden fields, and arrays. The scriptmanager control's scripts collection contains a scriptreference object for each script available in the browser. You can specify a script in declaration or programming mode.
The scriptmanager control also exposes registration methods. You can use these methods to programmatically manage client scripts and hide fields. When registering scripts or hidden fields that support partial page update, you must call the registration method of the scriptmanager control. (To register scripts that are not required for partial page update, use the clientscriptmanager class .)
Note: Any scripts registered using the scriptmanager control on the page and all event processing scripts must be placed in the form element on the page. Otherwise, the script is not registered or executed.
4. Register web services
To register a web service that you want to call from an ASP. NET page that supports Ajax, add the Web service to the services set of the scriptmanager control to register it. ASP. NET Ajax framework generates a client proxy object for each servicereference object in the services set. These proxies and their strongly typed members simplify the process of using web services from client scripts.
You can add the servicereference object to the services set programmatically to register the Web service at runtime.
5. Use authentication, configuration files, and role services from client scripts
Microsoft Ajax library contains a proxy class used to directly call ASP. NET 2.0 Forms authentication, configuration files, and role application services from JavaScript. To use the custom authentication service, you can use the scriptmanager control to register the service. For more information, see use forms authentication for ASP. NET Ajax, use configuration file information with ASP. NET Ajax, and use role information through ASP. NET Ajax.
6. scriptmanagerproxy class
Only one instance of the scriptmanager control can be added to the page. This page can directly include this control, or indirectly include it in nested components, such as user controls, master page content pages, or nested master pages. If the page already contains the scriptmanager control, but the nested components or parent components require other functions of the scriptmanager control, the component can contain the scriptmanagerproxy control. For example, the scriptmanagerproxy control enables you to add scripts and services specific to nested components.
Reprinted: http://blog.csdn.net/dodream/archive/2009/12/22/5058142.aspx