Reprint Ms Ajax

Source: Internet
Author: User

ASP. NET Ajax client lifecycle analysis (theoretical)
(1) Developer online builder.com.cn updated by: Author: Zhu Xianzhong Source: 51cto.com

Keyword: ASP. NET Ajax client Lifecycle

I. Introduction

Microsoft's ASP. NET Ajax framework, as a relatively complete Ajax framework, has many aspects worth further research. In this article, we will try to explore the client Lifecycle Process of ASP. NET Ajax framework with a specific example.

[Note] it is best to read this article in combination with the "ASP. NET application lifecycle overview" and "ASP. NET page lifecycle overview" articles.

Ii. ASP. NET Ajax client lifecycle Principle

Because ASP. the net Ajax framework greatly draws on ASP in terms of development ideas. NET 2.0 development technology, and will be gradually "included" to ASP.. NET 2.0. Therefore, an ASP. net Ajax page also has its own lifecycle, and with an ASP. NET 2.0 web page lifecycle is quite comparable.

Client events in ASP. NET Ajax pages support Custom User interfaces for traditional and asynchronous responses ("partial page refresh. In addition, these events can also help us manage and use custom scripts throughout the browser page lifecycle.

These client events are concentrated in the ASP. NET Ajax framework client class library. When a page with an ASP. NET Ajax Server Control is loaded, these classes are automatically instantiated by the framework. With some APIs provided by these clients, we can easily bind client events on the page. Because this part of the ASP. NET Ajax client library is completely independent from the browser, the code we write can certainly work in all the popular browser environments.

Among many client events, the most critical event is the load event of the application instance during the initialization request ('get' method) and asynchronous delivery.

[Note] When the script in the load event processor program starts running, all other scripts and components should be loaded and fully available.

When you use the Server Control updatepanel to refresh a local page, the most important events in all client events are the events related to the SYS. webforms. pagerequestmanager class. These important client events help you complete some common tasks, such as canceling the delivery, setting a higher priority for a delivery, and enabling the updatepanel control to produce certain animation effects during refresh. An in-depth understanding of all these client events will be of great help to create pages or develop components based on the ASP. NET Ajax framework. For example, if you are a web developer, you can use your own custom scripts during page loading and uninstallation.
Iii. client-side Parsing

As mentioned above, the SYS. Application class and SYS. webforms. pagerequestmanager class are the two most important classes throughout the lifecycle of the ASP. NET Ajax web page client. Next, we will analyze them one by one.

When a browser requests a page containing the scriptmanager control, the application class is instantiated. The application class is very similar to the page control on the server side (the page control inherits from the control class on the server side). However, it provides additional functions for server events. Similarly, the application class is derived from the SYS. component class of the client, but it triggers a series of client lifecycle events.

If a page contains a scriptmanager control and several updatepanel controls, the page can be partially updated (if the browser supports and starts the partial update function ). In this case, an instance of the pagerequestmanager class will be created and take effect on the browser side. In fact, client events caused by this pagerequestmanager instance are all about asynchronous delivery.
4. Add event processors for client events

To add or remove the corresponding event processor for events triggered by instances of the application class and pagerequestmanager class, we can use the add_eventname and reomve_eventname methods to complete these tasks. The following example shows how to add an event processor function named myload to the init event of the Application object:

SYS. application. add_init (myinit); // Add an event Processor
Function myinit (sender)
//............
SYS. appplication. remove_init (myinit); // remove the corresponding event processor.

This Code only describes the basic syntax of the operation. We will give an example later.

5. Process application load and unload events

Note: To handle the load and unload events of the Application object, you do not need to explicitly bind an event processor function to these events, instead, use the reserved keywords pageload and pageunload to create the corresponding function. The following example shows how to add an event processor function for the load event of the application.

Function pageload (sender, argS)

[Note] This is also true for online references-"You only need to use the reserved keywords pageload and pageunload to create the corresponding function: where can this detail be implemented? Interested readers can further explore a set of APIs that are downloaded along with the framework. This is actually somewhat "confusing" (it is estimated that the process is simple "obfuscation).

6. Events related to other clients

In this article, we focus only on the events provided by the application and pagerequestmanager classes (because events associated with these two classes play a crucial role in the lifecycle of the two client pages ). In fact, Microsoft's Ajax Class Library also includes a special class for Dom element event operations-sys. UI. domevent. The following are some typical global methods used to add, clear, and remove event processor functions. These methods include:

-SYS. UI. domevent. addhandler, abbreviated as $ addhandler;

-SYS. UI. domevent. clearhandlers, abbreviated as $ clearhandlers;

-SYS. UI. domevent. removehandler, abbreviated as $ removehandler.

However, the events provided by DOM elements are not discussed in this article (and are relatively simple ).

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.