Control execution Lifecycle (from MSDN)

Source: Internet
Author: User
Control | Every time a asp.net page is requested, the server loads a asp.net page and unloads the page when the request completes. The page and the server controls it contains are responsible for executing the request and rendering the HTML to the client. Although the communication between the client and the server is stateless and intermittent, the customer must feel that this is a sequential process.

This continuity illusion is implemented by ASP.net page frames, pages, and their controls. After a postback, the behavior of the control must appear to start where the last Web request ended. Although the ASP.net page framework makes execution state management relatively easy, control developers must know the order in which controls are executed in order to achieve continuity. Control developers need to understand what information the control can use at various stages of the control lifecycle, what data to keep, and in what state the control renders. For example, a control cannot call its parent until the control tree on the page is populated.

The following table provides a high-level overview of the stages in the control lifecycle. For more information, click on the link in the table.

The method or event to override for the action that the stage control needs to perform
Initializes the settings that are required to initialize the incoming WEB request life cycle. See Handling inherited events. Init Event (OnInit method)
Load view state at the end of this phase, the ViewState property of the control is automatically populated, as described in maintaining the status in the control. Control can override the default implementation of the LoadViewState method to customize the state restore. LoadViewState method
Processes postback data processing incoming forms, and updates properties accordingly. See Processing postback data.
Note Only controls that process postback data participate in this phase. LoadPostData method
(if IPostBackDataHandler is implemented)

Loads the operations that are common to all requests, such as setting up a database query. At this point, the server control in the tree has been created and initialized, the state has been restored, and the form control reflects the client's data. See Handling inherited events. Load Event
(OnLoad method)

Sending a postback change notification raises a change event in response to a state change between the current and previous postbacks. See Processing postback data.
Note Only controls that raise postback change events are involved in this phase. RaisePostDataChangedEvent method
(if IPostBackDataHandler is implemented)

Handles the client-side events that caused the postback and raises the appropriate event on the server for the postback event processing. See catching postback events.
Note Only controls that handle postback events participate in this phase. RaisePostBackEvent method
(if IPostBackEventHandler is implemented)

Pre-rendering performs any updates before rendering the output. You can save changes to the state of the control at the present stage, and changes that are made to the rendering phase are lost. See Handling inherited events. PreRender Events
(OnPreRender method)

Save state after this phase, the control's ViewState property is automatically persisted to the string object. This string object is sent to the client and sent back as a hidden variable. To improve efficiency, controls can override the SaveViewState method to modify the ViewState property. See maintaining the state in a control. SaveViewState method
Renders the output that the build renders to the client. See rendering ASP.net server controls. Render method
Disposes of all final cleanup operations before the destroy control is executed. References to expensive resources, such as database links, must be released at this stage. See methods in ASP.net server controls. Dispose method
Uninstalls all final cleanup operations before executing the destroy control. Control authors typically perform cleanup in Dispose without handling this event. UnLoad event (on UnLoad method)

Note To override the EventName event, override the OnEventName method (and call base. OnEventName).
The methods and events in the third column are inherited from System.Web.UI.Control, except for the following: LoadPostData and RaisePostDataChangedEvent are methods of the IPostBackDataHandler interface, And RaisePostBackEvent belong to the IPostBackEventHandler interface. If the control participates in postback data processing, the IPostBackDataHandler must be implemented. If the control receives a postback event, it must implement IPostBackEventHandler.

The CreateChildControls method is not listed in the table because it is called whenever the ASP.net page framework needs to create a control tree, and the method call is not limited to a specific stage of the control's lifecycle. For example, you can call CreateChildControls when you load a page, during the binding data process, or during the rendering process.




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.