1 Using System. Data;
2 Using System. configuration;
3 Using System. Web;
4 Using System. Web. Security;
5 Using System. Web. UI;
6 Using System. Web. UI. webcontrols;
7 Using System. Web. UI. webcontrols. webparts;
8 Using System. Web. UI. htmlcontrols;
9
10 Public Partial Class _ Default: Page
11 {
12 # Region Onpreinit Step 1
13 Protected Override Void Onpreinit (eventargs E)
14 {
15 // Check the ispostback attribute to determine whether the page is processed for the first time.
16 // Create or recreate a dynamic control.
17 // Dynamically set the master page.
18 // Set the theme attribute dynamically.
19 // Read or set the configuration file property value.
20 // Note:
21 // 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.
22 Base . Onpreinit (E );
23 }
24 # Endregion
25
26 # Region Oninit Step 2
27 Protected Override Void Oninit (eventargs E)
28 {
29 // Triggered after all controls have been initialized and all appearance settings have been applied. Use this event to read or initialize control properties.
30 Base . Oninit (E );
31 }
32 # Endregion
33
34 # Region Oninitcomplete step 3
35 Protected Override Void Oninitcomplete (eventargs E)
36 {
37 // Caused by a page object. This event is used to handle all tasks that require initialization to be completed first.
38
39 Base . Oninitcomplete (E );
40 }
41 # Endregion
42
43 # Region Step 4 of Preload
44 Protected Override Void Onpreload (eventargs E)
45 {
46 // The value of the HTML server control has been restored)
47 // Use this event to process pages or controls before loading events.
48 // 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.
49 Base . Onpreload (E );
50 }
51 # Endregion
52
53 # Region Step 5 of onload
54 Protected Override Void Onload (eventargs E)
55 {
56 // Page calls the onload event Method on the page, and then performs the same operation on each sub-control recursively,
57 // This repeats until the current page and all controls are loaded.
58 // Use the onload event method to set properties in the control and establish a database connection.
59 Base . Onload (E );
60 }
61 # Endregion
62
63 # Region Step 6
64 Protected Void Page_load ( Object Sender, eventargs E)
65 {
66 // What should I say? Everyone on Earth knows
67 // After execution, execute the page_load () event of the user control.
68 }
69 # Endregion
70
71 # Region Step 7
72 Protected Void Button#click ( Object Sender, eventargs E)
73 {
74 // These events are used to process specific control events, such as click events of the button control or textchanged events of the Textbox Control.
75 // Note:
76 // In the send-back request, if the page contains VerificationProgramCheck the isvalid attribute of the page and each validation control before performing any processing.
77 }
78 # Endregion
79
80 # Region Onloadcomplete Step 8
81 Protected Override Void Onloadcomplete (eventargs E)
82 {
83 // Use this event for tasks of all other controls on the page to be loaded.
84
85 Base . Onloadcomplete (E );
86 }
87 # Endregion
88
89 # Region Onprerender Step 9
90 Protected Override Void Onprerender (eventargs E)
91 {
92 // Before this event occurs:
93 // The Page Object calls ensurechildcontrols for each control and page.
94 // Each data binding control with the performanceid attribute is called the databind method.
95 // For more information, see the data binding event of the data binding control below.
96 // 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.
97
98 Base . Onprerender (E );
99 }
100 # Endregion
101
102 # Region Step 10 of savestatecomplete
103 Protected Override Void Onsavestatecomplete (eventargs E)
104 {
105 // Before this event occurs, viewstate is saved for the page and all controls. Any changes made to the page or control at this time will be ignored.
106 // Use this event to execute a task that meets the following conditions: You must have saved the view status, but have not made any changes to the control.
107
108 Base . Onsavestatecomplete (E );
109 }
110 # Endregion
111
112 # Region Render Step 1
113 // Render
114 // This is not an event; at this stage of processing, the page object calls this method on each control.
115 // All ASP. NET web server controls have a render method used to write the control flag sent to the browser.
116 // If you create a custom control, you usually need to override this method to output the tag of the control.
117 // 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.
118 // For more information, see develop custom ASP. NET Server controls.
119 // The user control (. ascx file) is automatically merged and rendered, so you do not needCodeExplicitly present the control.
120
121 # Endregion
122
123 # Region OnUnload Step 2
124 Protected Override Void OnUnload (eventargs E)
125 {
126 // 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,
127 // For example, close the connection to a specific database of the control.
128 // 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.
129 // Note:
130 // In the unload phase, the page and its controls have been rendered, so no further changes can be made to the response stream.
131 // If you try to call a method (such as the response. Write method), this page will cause an exception.
132
133
134 Base . OnUnload (E );
135 }
136 # Endregion
137 }
Execution sequence of master pages and content pages:
init of the control on the master page> init of the Content Page Control> init of the master page> init of the content page
-> load of the Content Page -> load on the master page> load on the control on the content page
prerender on the Content Page> prerender on the master page control> Content Page control prerender