The ScriptManager control is included in the ASP.net 2.0 AJAX extensions, which is used to process all components on the page as well as page local updates, generating related client-side proxy scripts to enable access to Web Service in JavaScript, There can be only one ScriptManager control on asp.net pages that need to support asp.net ajax. In the ScriptManager control we can specify the desired script library, or specify the Web Service to be invoked through JS, and call AuthenticationService and ProfileService, as well as page error handling.
Main content1. Control Overview 2. A simple example of 3. Client Script Mode 4. Error handling 5. Services Property 6. Scripts Property
one. Control OverviewThe ScriptManager control is included in the ASP.net 2.0 AJAX extensions, which is used to process all components on the page as well as page local updates, generating related client-side proxy scripts to enable access to Web Service in JavaScript, There can be only one ScriptManager control on asp.net pages that need to support asp.net ajax. In the ScriptManager control we can specify the desired script library, or specify a Web Service to be invoked through JS, and specify page error handling. Use <asp:ScriptManager/> to define a ScriptManager, simple ScriptManager definition form:
The properties and methods are as follows:
Properties/Methods |
Description |
Allowcustomerror |
Contact the custom error configuration area <customErrors> in web.config, use it, and the default value is True |
Asyncpostbackerrormessage |
A custom prompt error message when an error occurs in an asynchronous postback. |
Asyncpostbacktimeout |
Timeout limit for asynchronous postbacks, with a default value of 90, in seconds |
EnablePartialRendering |
Whether local updates to the page are supported, the default value is true, and generally do not need to be modified |
ScriptMode |
Specifies the mode of the script that ScriptManager sends to the client, with four modes: Auto,inherit,debug,release, the default value is Auto, and the following will be said carefully. |
ScriptPath |
Sets the root directory of all script blocks as global properties, including custom script blocks or script blocks referencing third parties. If the Path property is set in the <asp:ScriptReference/> tab in scripts, it overrides the property. |
Onasyncpostbackerror |
The service-side processing function When an exception occurs asynchronously, where a piece of information can be captured and processed accordingly. |
Onresolvescriptreference |
Specifies the server-side processing function of the Resolvescriptreference event, in which you can modify information about a script, such as the path, version, and so on. |
two. A simple exampleThis example is actually a updatepanel example, where a date control and a Drop-down box are added to the page, and the date control background changes to a different color depending on the selection of the Drop-down box. The sample code is as follows: <% @ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
< script runat = "server" >
void Dropdownselection_change (Object sender, EventArgs e)
{
Calendar1.DayStyle.BackColor =
System.Drawing.Color.FromName (ColorList.SelectedItem.Value);
}
</script >
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head ID = "Head1" runat = "server" >
< title > ScriptManager Example </title >
< BODY >
< form ID = "Form1" runat = "server" >
< div >
< Asp:scriptmanager ID = "ScriptManager1"
runat = "server" >
</Asp:scriptmanager >
< Asp:updatepanel