After referencing the Asp.net master page, the page event execution sequence of the master page and Content Page

Source: Internet
Author: User

The following steps are taken:

Step 2: page_preinit of the Content Page
Step 2. page_init of the master page
Step 2: page_init of the Content Page
Step 2: page_initcomplete on the Content Page
Step 2: page_preload of the Content Page
Step 2: page_load of the Content Page
Step 2: page_load of the master page
Send back events such as Button clicking on step 2, master page or content page (Button events of Master or content will not be triggered at the same time)
Step 2: page_loadcomplete on the Content Page
Step 2: page_prerender of the Content Page
Step 2: page_prerender on the master page
Step 2: page_prerendercomplete on the Content Page
Step 2: page_savestatecomplete on the Content Page
Step 2: page_unload on the master page
Step 2: page_unload of the Content Page

In addition, repost an article:Asp.net page event execution sequenceHttp://www.cnblogs.com/oletan/archive/2008/11/04/1326587.html#1549248)

Note: For ease of understanding, you can think that the onpreinit method is equivalent to the page_preinit method, and the onload method is equivalent to the page_load method.

In fact, the rewritten onpreinit method internally calls the page_preinit method above, and so on, the rewritten onload method calls the page_load method above.

If the base. onload (e) statement is not written in the override onload method, the page_load method will not be executed.

 

View plaincopy to clipboardprint?
  1. UsingSystem;
  2. UsingSystem. Data;
  3. UsingSystem. configuration;
  4. UsingSystem. Web;
  5. UsingSystem. Web. Security;
  6. UsingSystem. Web. UI;
  7. UsingSystem. Web. UI. webcontrols;
  8. UsingSystem. Web. UI. webcontrols. webparts;
  9. UsingSystem. Web. UI. htmlcontrols;
  10. PublicPartialClass_ Default: Page
  11. # Region onpreinit Step 1
  12. Protected Override VoidOnpreinit (eventargs E)
  13. {
  14. // Check the ispostback attribute to determine whether the page is processed for the first time.
  15. // Create or recreate a dynamic control.
  16. // Dynamically set the master page.
  17. // Set the theme attribute dynamically.
  18. // Read or set the configuration file property value.
  19. // Note
  20. // 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.
  21. Base. Onpreinit (E );
  22. # Endregion 
  23.  
  24. # Region oninit Step 2
  25. Protected Override VoidOninit (eventargs E)
  26. {
  27. // Triggered after all controls have been initialized and all appearance settings have been applied. Use this event to read or initialize control properties.
  28. Base. Oninit (E );
  29. # Endregion 
  30.  
  31. # Region oninitcomplete step 3
  32. Protected Override VoidOninitcomplete (eventargs E)
  33. {
  34. // Triggered by the Page Object. This event is used to handle all tasks that require initialization to be completed first.
  35. Base. Oninitcomplete (E );
  36. # Endregion 
  37.  
  38. # Region preload Step 4
  39. Protected Override VoidOnpreload (eventargs E)
  40. {
  41. // Use this event if you need to process pages or controls before loading events.
  42. // After a page event is triggered, it loads the view status for itself and all controls, and then processes any sending data included in the request instance.
  43. Base. Onpreload (E );
  44. # Endregion 
  45.  
  46. # Region onload Step 5
  47. Protected Override VoidOnload (eventargs E)
  48. {
  49. // Page calls the onload event Method on the page, and then performs the same operation on each sub-control recursively. This repeats until the current page and all controls are loaded.
  50. // Use the onload event method to set properties in the control and establish a database connection.
  51. Base. Onload (E );
  52. # Endregion 
  53.  
  54. # Step 6 of region control events
  55. Protected VoidButton#click (ObjectSender, eventargs E)
  56. {
  57. // Use these events to process specific control events, such as click events of the button control or textchanged events of the Textbox Control.
  58. // Note
  59. // In the send-back request, if the page contains VerificationProgramCheck the isvalid attribute of the page and each validation control before performing any processing.
  60. # Endregion 
  61.  
  62. # Region onloadcomplete Step 7
  63. Protected Override VoidOnloadcomplete (eventargs E)
  64. {
  65. // Use this event for tasks of all other controls on the page to be loaded.
  66. Base. Onloadcomplete (E );
  67. # Endregion 
  68.  
  69. # Region onprerender Step 8
  70. Protected Override VoidOnprerender (eventargs E)
  71. {
  72. // Before the event:
  73. // The Page Object calls ensurechildcontrols for each control and page.
  74. // The databind method is called for each data binding control with the performanceid attribute set. For more information, see the data binding event of the data binding control below.
  75. // 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.
  76. Base. Onprerender (E );
  77. # Endregion 
  78.  
  79. # Region savestatecomplete Step 9
  80. Protected Override VoidOnsavestatecomplete (eventargs E)
  81. {
  82. // 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.
  83. // Use this event to execute tasks that meet the following conditions: the view status is saved, but no changes are made to the control.
  84. Base. Onsavestatecomplete (E );
  85. # Endregion 
  86.  
  87. # Region render step 10
  88. // Render
  89. // 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.
  90. // 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.
  91. // The user control (. ascx file) is automatically merged and rendered, so you do not needCodeExplicitly present the control. 
  92.  
  93. # Endregion 
  94.  
  95. # Region onUnload Step 1
  96. Protected Override VoidOnUnload (eventargs E)
  97. {
  98. // 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.
  99. // For the page itself, use this event to perform the final cleaning, for example, closing the opened file and database connection, or completing logging or other request-specific tasks.
  100. // Note
  101. // When the page and its control are displayed, 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.
  102. Base. OnUnload (E );
  103. # Endregion
  104. }

 

From: http://blog.csdn.net/youbl/archive/2009/08/28/4492747.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.