Life cycle (lifecycle) and dynamic controls for pages in ASP.net 2.0

Source: Internet
Author: User
Tags visual studio

Original address: Http://www.codeproject.com/KB/aspnet/lifecycle.aspx

Author: Vivek Thakur

Introduced

Understanding the life cycle of the page (lifecycle) is important for developing asp.net applications. Many. NET beginners have issues such as losing value after postback and losing status when handling dynamically loaded controls. The HTTP protocol is stateless, which is a natural problem with Web programs and Windows programs, and if you want to learn asp.net, page's life cycle will be one of your most important foundations. What is the order of events, especially when ASP.net 2.0 has added a master page to make it more complex, the purpose of this article is to help you figure out what's going on in each event by explaining its order and its use.

Background

In a asp.net application, where users are always asking for an. aspx page, one of the things that interests us is what does the Web server that the application belongs to when the user accesses an. aspx page? Understanding the sequence of events will help us do what we want in the right events, or we can eliminate some of our confusion, such as blaming some of the problems on the state of the Web program.

Foundation: New compilation model and partial class (Partial Classes)

Each Web form in the ASP.net inherits directly or indirectly from the System.Web.UI.Page class. A web from includes two parts: one is a code file (WebForm.aspx.cs), it includes some events and methods associated with page, and the other is an ASPX file that includes some HTML control declarations (in Visual Studio 2005 of Web applications, we also have a design class called WebForm.aspx.designer.cs.

In asp.net 2.0, we do not need to define the control variables again, nor do we need to write some event delegates in the code file, thanks to some classes. In ASP.net 1.x, the code will automatically be generated in InitializeComponent (). But by the 2.0 version, runtime will create a partial class that contains all the information in the ASPX page. This makes the code file very clear and easy to manage.

This eliminates the association of names between code files and ASPX pages in VS2003 (if we want to change the ID of any control, we have to change the ASPX page and the code file). The events for all controls in VS2005 are defined in the ASPX page. So the event delegate and control variable in the code file will be cleared, which is more convenient than the previous VS2003.

The life cycle of a page

It is important to understand every request in the life cycle of a page, and the problem of lost or lost status may be caused by a lack of understanding of the life cycle of the page. Of course, if you want to keep your state in asp.net, you can use something like application,session,cache, or cookies.

Note: The view state in ASP.net 2.0 consists of two parts, control state and view state. For more information please refer to this article

Http://msdn2.microsoft.com/en-us/library/1whwt1k7 (vs.80). aspx

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.