ASP. net2.0 page execution sequence

Source: Internet
Author: User

I encountered a problem today. I added a judgment to the onload of masterpage. I want to execute the judgment before the onload of contentpage. The result shows that the onload of masterpage is executed after the onload of contentpage, later, I moved this judgment to the oninit of masterpage.

In a separate page, the execution order is

    1. Preinit
    2. Init
    3. Initcomplete
    4. Preload
    5. Load
    6. Loadcomplete
    7. Prerender
    8. Prerendercomplete

When masterpage is available on the page

    1. Contentpage. preinit
    2. Master. init
    3. Contentpage. init
    4. Contentpage. initcomplete
    5. Contentpage. Preload
    6. Contentpage. Load
    7. Master. Load
    8. Contentpage. loadcomplete
    9. Contentpage. prerender
    10. Master. prerender

Note that the highlighted part above is usually masterpage followed by contentpage.

So what is the relationship between widget loading and several page events?

Generally, the control on the page is executed before oninit, that is

    1. Init of the control in the master
    2. Init of the control in contentpage
    3. Master. init
    4. Content. init
    5. Content. Load
    6. Master. Load
    7. Master. User Control Load
    8. Page_load of the user control on the contentpage page

You can see that the control init is executed before the page init, so we can safely use the control in the page in init, but the following situations are different.

If your page uses webcontrol or controls inherited from webcontrol, webcontrol needs to use createchildcontrols () to load child controls. This function will be called after init of the control, that is to say, in oninit of a webcontrol, there is no way to directly use the control. However, we can also use findcontrol to load the control. The following table lists the loading sequence of other webcontrol methods.


Event Description
Init You can use the oninit method to trap this event
And initialize member variables and other values.
Loadviewstate You can trap this event to customize how
Control retrieves information from the ASP. NET hidden viewstate field.
Load This event is raised after you create and
Initialize the control. This is the best place to make the connection to
Database or load document content. you can trap the load event by adding
Onload Method to the class.
Prerender This event is raised before ASP. NET renders
Control. Any changes to the control's state are saved into the hidden viewstate
Field.
Saveviewstate This event is raised before the control state is
Persisted into the hidden viewstate field. You can trap the event to customize
How this information is stored.
Render You can use the render method to respond to this
Event and specify the HTML code that represents the component's
Content.
Dispose This event is useful for cleanup operations. It's
Raised before the control is torn down and is the best place to free
Resources created during the load phase.
Unload This event is raised before the control is torn
Down. The official documentation says not to use this event to perform cleanup,
And to rely on the dispose event
Instead.

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.