page event execution sequence

Source: Internet
Author: User

using system;
using system. data;
using system. configuration;
using system. web;
using system. web. security;
using system. web. ui;
using system. web. UI. webcontrols;
using system. web. UI. webcontrols. webparts;
using system. web. UI. htmlcontrols;

Public Partial Class_ Default: Page
Protected VoidPage_load (ObjectSender, eventargs E)


# RegionOnpreinit Step 1
Protected Override VoidOnpreinit (eventargs E)
//Check the ispostback attribute to determine whether the page is processed for the first time.

//Create or recreate a dynamic control.

//Dynamically set the master page.

//Set the theme attribute dynamically.

//Read or set the configuration file property value.

//If the request is a send-back request, the value of the control has not been restored from the view State. If the control property is set in this phase, its value may be overwritten in the next event.

Base. Onpreinit (E );
# Endregion

# Region Oninit Step 2
Protected   Override   Void Oninit (eventargs E)
// Triggered after all controls have been initialized and all appearance settings have been applied. Use this event to read or initialize control properties.
Base . Oninit (E );
# Endregion

# Region Oninitcomplete step 3
Protected   Override   Void Oninitcomplete (eventargs E)
// Caused by a page object. This event is used to handle all tasks that require initialization to be completed first.

Base . Oninitcomplete (E );
# Endregion

# region step 4 of preload
protected override void onpreload (eventargs e)
{< br> /// use this event to process pages or controls before loading events.

//After page raises this event, it loads the view status for itself and all controls, and then processes any sending data included in the request instance.

Base. Onpreload (E );
# Endregion 

# Region Step 5 of onload
Protected   Override   Void Onload (eventargs E)
// The page calls the onload event Method on the page, and then performs the same operation on each sub-control recursively, until the page and all controls are loaded.
// Use the onload event method to set properties in the control and establish a database connection.

Base . Onload (E );
# Endregion

# RegionStep 6
Protected VoidButton#click (ObjectSender, eventargs E)
//These events are used to process specific control events, such as click events of the button control or textchanged events of the Textbox Control.

//In the send-back request, if the page contains VerificationProgramCheck the isvalid attribute of the page and each validation control before performing any processing.

# Endregion

# Region Step 7 of onloadcomplete
Protected   Override   Void Onloadcomplete (eventargs E)
// Use this event for tasks of all other controls on the page to be loaded.

Base . Onloadcomplete (E );
# Endregion

# RegionOnprerender Step 8
Protected Override VoidOnprerender (eventargs E)
//Before this event occurs:

//The Page Object calls ensurechildcontrols for each control and page.

//Each data binding control with the performanceid attribute is called the databind method. For more information, see the data binding event of the data binding control below.

//A prerender event occurs for each control on the page. Use this event to make the final changes to the page or its control content.

Base. Onprerender (E );
# Endregion 

# region Step 9 of savestatecomplete
protected override void onsavestateco Mplete (eventargs e)
{< br> /// viewstate is saved for the page and all controls before this event occurs. Any changes made to the page or control at this time will be ignored.

// use this event to execute a task that meets the following conditions: the view status is saved, but no changes are made to the control.

base . onsavestatecomplete (E);
}< br> # endregion

# RegionStep 10 of render
//This is not an event; at this stage of processing, the page object calls this method on each control. All ASP. NET web server controls have a render method used to write the control flag sent to the browser.

//If you create a custom control, you usually need to override this method to output the tag of the control. However, if the custom control only merges the standard ASP. NET web server control and does not merge the custom tag, the render method is not required. For more information, see develop custom ASP. NET Server controls.

// User Control (. ascx files) are automatically merged and rendered, so you do not need to explicitly present the control in Code .

# endregion

# RegionOnUnload Step 2
Protected Override VoidOnUnload (eventargs E)
//This event first occurs for each control and then for this page. In the control, use this event to perform final cleaning on the specific control, for example, closing the connection to the specific database of the control.

//For the page itself, use this event to perform the final cleanup, such as closing open files and database connections, or completing logging or other request-specific tasks.

//In the unload phase, the page and its controls have been rendered, so no further changes can be made to the response stream. If you try to call a method (such as the response. Write method), this page will cause an exception.

Base. OnUnload (E );
# Endregion

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: 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.