ASP. NET page parsing (3)

Source: Internet
Author: User

Event Model

When a page is requested, its class and its server control are responsible for processing the request, rendering the HTML output, and then sending it back to the client. Due to the inherent characteristics of the HTTP protocol, communication between the client and the server is stateless and non-connected. Practical ApplicationProgramStatus is required to maintain subsequent calls to the same page. With ASP or other server-side development platforms (such as Java Server Page and lamp Linux-based systems), developers must be responsible for state storage. ASP. NET provides a built-in architecture to store and restore the page status in a transparent manner. Although it is based on the stateless protocol, in this way, the client experiences a continuous execution process. However, it is just a representation.

View status overview

This kind of representation caused by continuity is related to the design of pages and work methods, and ASP. NET page view status. At the same time, server-side controls also play an important role. In short, before a page shows its content as HTML, the page stores its own status information and its contained controls in the persistent medium (generally an implicit field. After the page is sent back, its status is deserialized from the hidden field to initialize the Server Control Instance declared in the page layout. Each page instance has its own view status because the information is embedded in HTML. The advantage of doing so is that the control initializes the value of the view State created at the previous time (that is, the status when the page was last rendered to the client. In addition, there is a stage in the page cycle to merge the stored status with the updates made by the client. After sending a message back, when the page is executed, it will find a stateful and updated context, just like working on a continuous point-to-point connection. Two assumptions are made here. The first assumption is that the page is always delivered to itself and carries status information. The second assumption is that the server-side control must have the runat = server attribute so that the control can be "alive" after the page is sent back ".

Single Form Model

It is undeniable that programmers with ASP or JSP experience may not be able to adapt to the single form model of ASP. NET at the beginning. These programmers often ask the following question in forums and newsgroups: "Where is the form action attribute ?" And "Why cannot I redirect to a specific page when submitting a form ?" The ASP. NET page supports only one server <form> label. All controls to interact with the server must be placed in the form. Both the form and control must have the runat attribute. Otherwise, the form and control are regarded as plain text and output word by word. On the server side, the form is an instance of the htmlform class. The htmlform class does not expose any action attributes that are equivalent to the HTML <form> tag. The reason is that ASP. NET pages are always delivered to themselves. In addition to the action attribute, other common attributes (such as method and target) of the form are fully supported. Pages that do not contain server-side forms and use HTML forms (<form> tags without the runat attribute) are also valid ASP. NET pages. On the ASP. NET page, HTML and Server Forms can coexist. However, you can only set the runat attribute of one <form> label to server. HTML forms can be shipped to any page in the program, as in general. However, the problem is that the status information is not automatically stored. In other words, the ASP. NET web form model works only when the form uses a server <form> element.

Asynchronous page

The ASP. NET page is processed by an HTTP handler as an instance of the page class. Each request occupies a thread in the ASP. NET thread pool and is released only after the request is completed. What if the requested page frequently starts external and time-consuming tasks? The problem is that although the ASP. NET process is idle, there is no idle thread in the pool to process requests from other new pages. This should be attributed to the synchronous operation of HTTP processing programs (including page classes. To alleviate this problem, ASP. NET supports asynchronous processing programs (through the ihttpasynchandler Interface) Since Version 1.0 ). Since ASP. NET 2.0, it is easier to create an asynchronous page with the support of the framework. Asynchronous ASP. NET page construction involves two aspects: A New attribute of the @ page command and several registered asynchronous execution tasks. Asynchronous tasks can be registered in two ways. You can define an asynchronous handler begin/end pair for the prerendercomplete event, or create a pageasynctask object that represents an asynchronous task. This can be performed before the prerender event is triggered, but it is generally in the page_load event.

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.