Simplified: ASP. NET event trigger sequence

Source: Internet
Author: User
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 {# region onpreinit Step 1: The view is not restored (the control attribute setting is invalid). Here theme is set ), read/write configuration file attributes protected override void onpreinit (eventargs e) {}# endregion # region oninit Step 2: Triggered after all controls have been initialized and all appearance settings have been applied. Use this event to read or initialize control properties. Protected override void oninit (eventargs e) {}# endregion # region oninitcomplete Step 3: triggered by the Page Object. This event is used to handle all tasks that require initialization to be completed first. Protected override void oninitcomplete (eventargs e) {}# endregion # region preload Step 4: restore the value of the HTML Server Control (the value has been restored ), the system then processes any returned data contained in the request instance. Protected override void onpreload (eventargs e) {}# endregion # region onload Step 5: perform the same operation on each sub-control recursively, Set Properties in the control, and establish a database connection. Protected override void onload (eventargs e) {}# endregion # region Step 6: After the execution, execute the page_load () event protected void page_load (Object sender, eventargs E) of the user control) {} # endregion # step 7 of the region control event: Control event, such as the Click Event of the button control or textchanged event of the Textbox Control. Protected void button#click (Object sender, eventargs e) {}# endregion # region onloadcomplete Step 8: use this event for tasks that require all other controls on the page to be loaded. Protected override void onloadcomplete (eventargs e) {}# endregion # region onprerender Step 9: each data binding control with the performanceid attribute is called by the databind method, use this event to make the final changes to the page or its control content protected override void onprerender (eventargs e) {}# endregion # region savestatecomplete Step 10: any changes made to the page or control at this time will be ignored. Protected override void onsavestatecomplete (eventargs e) {}# endregion # region render Step 1 // 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 control tag. // 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. // The user control (. ascx file) is automatically merged and rendered, so you do not needCode Explicitly present the control. # Endregion # region onUnload Step 1: This event first occurs for each control and then for this page. In the control, use this event to perform the final cleanup on the specific control. Protected override void onUnload (eventargs e) {}# endregion}

both the master page and content page can contain the event processing Program of the control. for controls, events are processed locally, that is, controls on the Content Page trigger events on the Content Page, and controls on the master page trigger events on the master page. control events are not sent from the content page to the master page. Similarly, you cannot process events from the master page control in the Content Page.

in some cases, the same event is triggered on the Content Page and master page. init and load events. "> for example, both of them trigger init and load events. The general rule for triggering an event is that the initialization event is triggered from the innermost control to the outermost control, and all other events are triggered from the outermost control to the innermost control. Remember that the master page is merged into the content page and considered as a control in the content page, which is useful at 01:10.

The following shows the sequence of events after the master page and content page are merged:

  1. Content PagePreinitEvent.

  2. Master Page ControlInitEvent.

  3. Content ControlInitEvent.

  4. Master pageInitEvent.

  5. Content PageInitEvent.

  6. Content PageLoadEvent.

  7. Master pageLoadEvent.

  8. Master Page ControlLoadEvent.

  9. Content Page ControlLoadEvent.

  10. Content PagePrerenderEvent.

  11. Master pagePrerenderEvent.

  12. Master Page ControlPrerenderEvent.

  13. Content Page ControlPrerenderEvent.

  14. Master Page ControlUnloadEvent.

  15. Content Page ControlUnloadEvent.

  16. Master pageUnloadEvent.

  17. Content PageUnloadEvent.

the event sequence on the master page and content page is not important to page developers. however, if the event handler you create depends on the availability of some events, you will find it helpful to understand the event sequence on the master page and content page.

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.