This article is about translation.
Xiao Q
In the previous article, we introduced partial page refresh through simple small examples. In this article, we will introduce the attributes and methods of scriptmananger, one of the most important controls of Microsoft Ajax.
1. client-related attributes
Attribute |
Type |
Description |
Allowcustomeerrorsredirect |
Bool |
Define whether to use webconfig to customize error handling |
Asyncpostbackerrormessage |
String |
Defines the error message displayed on the client when an error occurs. |
Asyncpostbacktimeout |
Int32 |
Gets or sets a value that indicates the time (in seconds) before the asynchronous sending timeout when no response is received ). |
Enablescriptglobalization |
Bool |
Gets or sets a value that indicates whether the scriptmanager control displays a script that allows you to analyze specific regional information and set its format. |
Enablescriptlocalization |
Bool |
Gets or sets a value that indicates whether the scriptmanager control displays the localized version of the script file. |
Scriptloadtimeout |
Int32 |
Defines the maximum time for script installation on the client. |
Scriptmode |
Enum (Auto, debug, release, inherit) |
Gets or sets a value to specify whether to display the debug version or release version of the client script library. |
Scriptpath |
String |
Obtains or sets the root path of a location. This location is used to create a path pointing to ASP. NET Ajax and a custom script file. |
2): Background attributes
Attribute |
Type |
Description |
Authenticationservice |
Authenticationservice-Manager |
Gets the authenticationservicemanager object associated with the current scriptmanager instance. |
Isdebuggingenabled |
Bool |
Obtains a value indicating whether to display the debug version of the client script library. |
Isinasyncpostback |
Bool |
Gets a value indicating whether to execute the current sending back in partial rendering mode. |
Profileservice |
Profileservicemanager |
Gets the profileservicemanager object associated with the current scriptmanager instance. |
Scripts |
Collection <scriptreference> |
Obtain a scriptreferencecollection object that contains a scriptreference object (each object represents a script file presented to the client. |
Services |
Collection <servicereference> |
Obtain a servicereferencecollection object that contains the servicereference object of each Web Service exposed by ASP. NET on the client for Ajax. |
Supportspartialrendering |
Bool |
Obtain a value indicating whether the client supports partial page rendering. |
3) scriptmanager related methods
Name |
Type |
Description |
Setfocus (string) |
Void |
When the request ends, set the browser focus to the specified control. |
4) subitem of scriptmanager
Tag |
Description |
<Authenticationservice> |
Provides detailed instances of ASP. NET authentication service. |
<Profileservice> |
Provides detailed instances of ASP. NET Profiling Service. |
<Scripts> |
Provide additional Script Reference |
<Asp: scriptreference> |
Special Script Reference |
<Service> |
Obtain a servicereferencecollection object that contains the servicereference object of each Web Service exposed by ASP. NET on the client for Ajax. |
<Asp: servicereference> |
|
The scriptmanager control is ASP. net Ajax extensions core. it provides access to the script Library (including other extended Script Type Systems. it supports partial rendering of web pages, and also provides other ASP.. Net WebService (such as authentication, profiling, and other WebServices. in addition. the scriptmanager control supports the globalization and localization of client scripts.
Provides scripts that can be selected and appended
Although ASP. NET 2.0 Ajax Extensions contains the entire script code in the debugging and release versions, developers can freely set custom script files like registering other scripts.
To reload the default built-in scripts. you can register a resolvescriptreference event in the scriptmanager class. when this method is called. the event processor will automatically change the script path, and scriptmanager will send copies of different or custom scripts to the client/
Updatepanels custom error handling
Although the update is triggered by the updatepanel control. however, the error handling and custom error information are still handled through the scriptmanager control. the exception handling logic is displayed through asyncpostbackerror on the page. you can set the displayed error information through the asyncpostbackerrormessage attribute.
Of course, you can use the custom error handling mechanism of the client.
Example: Listing 5: client-side script to display custom errors
<SCRIPT type = "text/JavaScript">
<! --
SYS. webforms. pagerequestmanager. getinstance (). add_endrequest (request_end );
Function
Request_end (sender, argS)
{
If (ARGs. get_error ()! =
Undefined)
{
VaR errormessage =
"";
If (ARGs. GET_RESPONSE (). get_statuscode () = "200
")
{
Errormessage =
Args. get_error (). message;
}
Else
{
// The server wasn' t the problem errormessage = "an unknown error occurred ";
}
// Do something with the errormessage here.
// Now make sure the system knows we handled the error.
Args. set_errorhandled (true
);
}
}
// -->
</SCRIPT>
The method is quite simple. the above script registers the callback at the end of the asynchronous call. it checks for errors. if any, obtain the error details and notify the user that the runtime error has been processed by the custom script.