Asp: ScriptManager)

Source: Internet
Author: User
Asp: ScriptManager)
  • The client script function of the Microsoft AJAX library and any custom scripts to be sent to the browser.
  • Some page outputs, so that a certain area of the page can be refreshed without relying on delivery. The UpdatePanel, UpdateProgress, and Timer controls of ASP. net ajax require the ScriptManager control to support partial output.
  • Web service Javascript proxy, which allows client scripts to access the methods exposed by strong Web services.
  • Javascript access ASP. NET authentication and personalized application services.
1.1 make some page outputs available
When one or more UpdatePanel controls exist on the page, the ScriptManager control manages local page output in the browser. Controls interact with page generation cycles to update partial pages contained in the UpdatePanel control. The EnablePartialRendering attribute of the ScriptManager control determines whether the page can be partially updated. By default, the value of EnablePartialRendering is true. Therefore, when a ScriptManager control is added to the page by default, partial output is available. 1.2 handle errors
During local output, you can use the following methods to handle errors:
  • Set the AllowCustomErrorsRedirect attribute, which determines how to use the custom error section of the Web. config file when an error occurs during asynchronous sending.
  • Handles the AsyncPostBackError event of the ScriptManager control, which is triggered when a page error occurs during asynchronous sending.
  • Set the AsyncPostBackErrorMessage attribute, which is an error message sent to the browser.
1.3 Use Type System Extension
The Microsoft AJAX Library adds Javascript type system extensions and provides namespaces, inheritance, interfaces, enumeration, reflection, and auxiliary functions for strings and arrays. These extensions provide functions in client scripts to make them look like a. NET Framework. It allows you to write ASP. NET 2.0 AJAX extension applications in a structured way to enhance maintainability, make it easier to add features and divide functional layers. Adding the ScriptManager control to the ASP. NET Web page will automatically include the type system extension, so you can use the library in the client script. 1.4 register a custom script
Use ScriptManager to manage resources created for controls that participate in partial page updates. resources include scripts, styles, hidden fields, and arrays. The Scripts set of the ScriptManager control includes the ScriptReference object of the Scripts available for each browser. You can specify a script using declaration or programming. The ScriptManager control also provides methods for managing client scripts and hiding fields programmatically. When registering scripts and hidden fields that support partial page updates, you must call the ScriptManager registration method. (You can use the ClientScriptManager class to register scripts not required for partial page updates .) Note:
Any script registered by the ScriptManager control on the page and all event processing scripts must be included in Element. Otherwise, the script will not be registered or executed. 1.5 register a Web service
The Services set of the ScriptManager control contains the ServiceReference object of each Web service registered using ScriptManager. The ASP. net ajax framework generates a client proxy object for each ServiceReference object in the Services set. The proxy class and its strongly-typed members simplify the use of Web services by client scripts. You can add the ServiceReference object to the Services Collection programmatically during running to register the Web service. 1.6 use authentication and personalized services in client scripts
The Microsoft AJAX Library contains a proxy class that calls ASP. NET 2.0 form authentication and personalized application services directly from Javascript. To use a custom authentication service, you can use the ScriptManager control to register the service. 1.7 ScriptManagerProxy class
Only one ScriptManager control can be added to a page. A page can contain controls directly or nested components, such as user controls, content pages on a master page, or nested master pages. Welcome Xuewang, Add this article to favorites[1] [2] [3] $ False $

When the page already has a ScriptManager control, and the nested or parent component needs other features of the ScriptManager control, the component can contain a ScriptManagerProxy control. For example, the ScriptManagerProxy control allows you to add scripts and services for nested components only to corresponding components.
2. add the ScriptManager control.
Drag the ScriptManager control from the toolbox toElement to get the following element reference, so that ASP. NET AJAx can be used on all its pages.

3 Client script management example
3.1 and 3.2 respectively demonstrate how to add a script embedded in a single set of programs or an independent script file to the page. if you want to add multiple scripts at the same time, follow these two methods at will Add multiple elements to the element. 3.1 add scripts embedded in the Assembly
The following code adds the PreviesScript. js script file embedded in the Microsot. Web. Preview assembly to the page.
3.2 add a separate script file
The following code adds a separate script file to the page ~ /ScriptPath/ScriptFile. js. you can replace it with the script file you need.
3.3 Attributes of ScriptManager
ScriptMode:
Both ScriptManager and ScriptReference objects have the ScriptMode attribute. it determines whether the version of the script sent to the client is Debug or Release. It has four optional values: Inherit, Auto, Debug, and Release. The meaning of Debug and Release is very clear, so it will not be explained. Inherit indicates inheriting the outer settings. for ScriptManager, it is equivalent to Auto. Auto indicates that the script version is automatically determined based on the current compilation mode and related settings in Web. config. ScriptPath:
Specifies the relative, absolute, or application-related URLs of all script blocks on the page, including custom or third-party script blocks registered by the current ScriptManager instance. If the Path attribute is set for the ScriptReference in the Scripts set, the Path attribute overwrites the ScriptPath setting. If this attribute is not set and ScriptReference specifies an assembly, WebResource is used for each request. after the axd parses the script from the assembly and returns it to the browser, the js file under ScriptPath will be used directly after the setting. LoadScriptsBeforeUI:
When this attribute is true, the script element generated for the introduced script appears before the UI tag of all pages; otherwise, it is generated after all UI tags. If you need to use the imported script for execution during the loading process, you must set it to true. Otherwise, the script cannot be executed.
4. add a Web service client proxy
Adding a Web service client proxy is similar to adding a script, as shown in the following code:

Unat = "server"> In addition, the following configuration items must be added to Web. config:
In this way, you can directly call the static method of the Web service in the client script.
5. handle exceptions in asynchronous sending back
Only the simplest method is described here. Generally, when an exception occurs ,. NET Framework will redirect to a yellow. color exception page, but for pages that are processed using asynchronous sending back, this is a disaster and cannot be restored to the current status of the original page. You can set the AllowCustomErrorsRedirect = "false" of the ScriptManager control to prevent redirection when an exception occurs. set the AsyncPostBackErrorMessage attribute to the error message displayed to the user when an exception occurs. In this way, when an exception occurs, ScriptManager will automatically pop up a browser message box containing information set in AsyncPostBackErrorMessage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.