Embrace change-from Atlas to ASP. net ajax (2): the ever-changing ScriptManager (Dflying still has many questions, please advise)

Source: Internet
Author: User

Before reading this article, you must install Microsoft ASP. net ajax v1.0 Beta and Microsoft ASP. net ajax ctp Beta, where the latter depends on the former, you need to pay attention to the installation sequence (see embrace changes-from Atlas to ASP. net ajax (1): download and install Overview ). After the installation is complete, two templates will be added when you create a Web Site in Visual Studio:ASP. net ajax Enabled Web SiteAndASP. net ajax ctp Enabled Web SiteThe former is the most basic Microsoft ASP. net ajax v1.0 Beta site, which is based on the former extension, that is, Microsoft ASP. net ajax ctp Beta site, including multiple additional controls (these are also in the original Atlas ). By the way, Microsoft. web. extensions. dll, that is, Microsoft ASP. net ajax v1.0 Beta DLL will be automatically added to GAC during installation, which is precisely the creation of ASP. net ajax Enabled Web Site. Microsoft. web. preview. dll, that is, Microsoft ASP. net ajax ctp Beta DLL is not added to GAC, so ASP is created. net ajax ctp Enabled Web Site, the DLL is included in the bin folder.

The following content is based on a newly created ASP. net ajax Enabled Web Site.

In ASP. net ajax, The ScriptManager control still exists on the page as the core component, and is responsible for sending the JavaScript script that implements Ajax on the client to the browser. However, from Atlas to ASP. net ajax, the changes in ScriptManager can be called a face-to-face change, almost revolutionizing all the previously familiar concepts of ScriptManager in Atlas.

The client script library files of ASP. net ajax are greatly reduced. It seems that Microsoft is aware of the shortcomings of Atlas:

  1. MicrosoftAjax. js 67KB
  2. MicrosoftAjaxRuntime. js 15KB
  3. MicrosoftAjaxWebForms. js 32KB
  4. PreviewDragDrop 42KB
  5. PreviewGlitz. js 14KB
  6. PreviewScript. js 183KB

The first three are the core script libraries in Microsoft ASP. net ajax v1.0 Beta, and the last three are additional script libraries in Microsoft ASP. net ajax ctp Beta. NotesBoth AtlasCompact. js and AtlasCompact2.js browsers have no compatibility layer files., And everything is integrated into MicrosoftAjax. js.

Note:: Many of the content in this article is my personal opinions learned tonight. It has not been well verified and many questions have been raised in the article. I hope my friends can help solve this problem.

Let's explain the changes one by one from the declaration of the ScriptManager labels:

<Asp: ScriptManager> label

Note that the original "altas" prefix is changed to "asp ". It is said that it is to be "seamless" with the existing ASP. NET interface, but I do not agree, after all, different prefixes are easier to distinguish.

After adding a simple <asp: ScriptManager>, three scripts are imported to the client: MicrosoftAjax through the axd resource file. js, MicrosoftAjaxWebForms. js and another JavaScript file (question: What is this? What is the purpose ?).

Another question is, how should Microsoft tajaxruntime. js of this simplified version be used? <Asp: ScriptManager> the tag does not seem to provide the setting options for using the script? Can it be introduced manually?

Let's put down these two questions and take a look at the attributes supported by the <asp: ScriptManager> tag:

  1. AllowCustomError: Specifies whether to use the <customErrors> section in Web. config when an asynchronous update exception occurs. In <customErrors>, you can specify the application-level error handling page. If we are relatively lazy, you can set this attribute to true to enable normal ASP after an exception occurs.. NET programs are redirected to a page that specifically displays errors. Generally, it is best to set it to false because this is an Ajax program and page Jump should be avoided.
  2. AsyncPostBackErrorMessage: The error message sent to the client when an exception occurs during asynchronous update.AsyncPostBackErrorThe event handler dynamically sets this information based on the exception. Then the client Web Form framework can be formatted and displayed to the user, which is also my recommended Ajax exception handling method.
  3. AsyncPostBackTimeout: Time-out period of asynchronous update, in seconds. The default value is 90. Nothing to say. Don't change it if it's okay.
  4. EnablePartialRendering(I finally saw an attribute in Atlas, so excited ......) Whether partial page update is supported. The default value is set to true. Therefore, when using UpdatePanel, you do not have to pay attention to setting this attribute for ScriptManager every time, but it naturally has a slight effect on efficiency. Which of the following methods is the best? This is also the question of the benevolent and wise.
  5. ScriptMode: Specifies the version (Debug or Release) that uses the client script, and the setting results for this property are also subject to retail-related settings in the configuration file. For details, see the http://ajax.asp.net/docs/mref/332fcb41-e4ab-4c1f-bb5e-61b49035af74.aspx. Note that for custom scripts, if this attribute is set to Debug or the script of the Debug version is considered to be required to be loaded when the program is running, the script file name will automatically add a "debug" section, for example, "myjs. js will automatically become "myjs. debug. js ". (It seems a little weird, too many pre-agreements, maybe not a good thing)
  6. ScriptPath: This attribute makes me very depressed! The official explanation is "as the root directory (Global Path) of all script files )". According to my understanding, this attribute is designed to easily replace a script of an existing version without having to change it one by one in each <asp: ScriptReference>. After this attribute is set, for example, /Dflying, the reference method of the client script will change to "<script src = "~ Dflying/Microsoft. web. extensions/1.0.61025.0/Microsoft. web. resources. scriptLibrary. microsoftAjax. debug. static script reference such as js "type =" text/javascript "> </script>" instead of obtaining it through the axd resource by default, the format is "ScriptPath + set name + version number + script file name ". In this way, if we modify a script that comes with the framework, we can use this method to introduce the modified New JavaScript file into the program, the reference method of this static file has unconsciously improved the execution efficiency of the program.
  7. OnAsyncPostBackError: SpecifyAsyncPostBackErrorThe server-side processing function of the event. In this processing function, we can obtain the exception that is thrown, and set differentAsyncPostBackErrorMessageTo give users friendly prompts.
  8. OnResolveScriptReference: SpecifyResolveScriptReferenceThe server-side processing function of the event. In this processing function, we can modify the information about a script, such as the path, name, and version (Debug or Release.

 

Next, let's take a look at the changes in each seed tag in the <asp: ScriptManager> tag:

<ErrorTemplate> tag

Delete the entire file. With the AsyncPostBackErrorMessage attribute, OnAsyncPostBackError event, and the client Web Form framework, we developers can flexibly customize the abnormal display interface instead of being limited to the original <ErrorTemplate>.

The default display interface for asynchronous update exceptions in ASP. net ajax is a simple JavaScript alert () dialog box.


<Asp: ScriptReference> tag

The <asp: ScriptReference> tag is included in the <Scripts> tag to introduce a client JavaScript script to the page. If you need to use additional scripts in Microsoft ASP. net ajax ctp Beta or custom scripts compiled by yourself, use this label to introduce them. <Asp: ScriptReference> support for ScriptName enumeration is removed from tags. Currently, the following attributes are supported:

  1. Assembly: The Assembly embedded with the script to be referenced.
  2. Name: The Resource Name of a script embedded in the Assembly. The preceding two attributes are usually used in pairs, for example, <asp: ScriptReference Name = "Microsoft. web. resources. scriptLibrary. previewGlitz. js "Assembly =" Microsoft. web. preview "/> introduces Microsoft. web. preview. the name in dll is Microsoft. web. resources. scriptLibrary. previewGlitz. javaScript resources.
  3. Path: Specify the custom script file to be referenced through the path.
  4. ScriptMode: Defines the attributes of the same name in the <asp: ScriptManager> label and overwrites the settings. It is also worth noting that if this attribute is set to Debug or the script of the Debug version is considered to be loaded when the program is running, the script file name will automatically add a "debug" part, for example, "myjs. js will automatically become "myjs. debug. js ".
  5. IgnoreScriptPath: Whether to ignore the definition of the ScriptPath attribute in the <asp: ScriptManager> label.

 

<Asp: ServiceReference> label

The GenerateProxy, OnScriptLoad, and Type attributes are removed. Only the following two items are left:

  1. InlineScript: Whether to inline this Proxy to the page. inline to the page will save an HTTP connection, which will slightly Speed Up Program initialization.
  2. Path: The file path of the Web Service.

 

<AuthenticationService> label

  1. Path: Verify the file path of the service.

 

<ProfileService> label

  1. Path: File path of the user's personalized service.
  2. LoadProperties: Inline User Personalization attributes on the page.

For the <AuthenticationService> and <ProfileService> labels, it seems to be related to AuthenticationServiceManager and ProfileServiceManager respectively, and will also be used in the client Web Form model ...... I don't have enough time tonight to study it in depth. Q: How to use these two items? If you know me, please let me know.

 

Postscript

The time is too short, the text is a little hasty, and it is not too smooth. Naturally, it will be difficult to understand in many places. Please also ask your friends, Hai Han! As I started to get started from the beginning, there will certainly be many mistakes. Please do not hesitate to criticize and advise, or discuss and share your experiences!

Thank you for your support!

Related Article

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.