In the previous blog, I introduced the principles of ASP. NET page access, as well as the execution sequence of sending back pages and controls. This is because the description of the text may not be so clear. Therefore, this blog is intended to use an example to illustrate.
Review
As mentioned in the previous blog, the web application must submit the form of the client to the server for execution and send it back to the client on the html page generated. In this case, a Pageload event will be executed every time after the form is submitted. Events of input controls such as textbox and DropDownList will not always respond to your operations.
Rough event execution sequence
The events here are incomplete, and the general functions of each event are not complete. If you are interested, check the information on the Internet. Recommended URLs. Only the event sequence is not explained: ASP. Net Event Sequence
1) Perlnit:
① Use 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 attribute is set in this phase, the value may be overwritten in the next phase.
2) lint: read or initialize control attributes
3) lintComplete
4) PerLoad
5) PageLoad
6) control Load
7) control events
8 )......
9) Render
10) PageUnload
Instance
Originally, we wanted to describe the events before pageload. It's not easy to think about it. Here, we will only illustrate the execution sequence of control events.
HTML page:
Code:
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; public partial class Sample_003: System. web. UI. page {int I = 1; protected void Page_Load (object sender, EventArgs e) {// This text box txt_result.Text = ""; txt_result.Text = I ++ is cleared every time the Page is loaded. toString () + ": PageLoad" + "\ n";} protected void TextBox1_TextChanged (object sender, EventArgs e) {txt_result.Text ++ = I ++. toString () + ": TextChanged" + "\ n";} protected void DropDownList1_SelectedIndexChanged (object sender, EventArgs e) {txt_result.Text ++ = I ++. toString () + ": SelectChanged" + "\ n";} protected void button#click (object sender, EventArgs e) {txt_result.Text ++ = I ++. toString () + ": ButtonClick" + "\ n ";}}
Summary
HTML is simple, just give it. You can debug the code yourself. After running it on your own, you will find that the first event has always been a PageLoad event (because the code was not written in the code before this event), and the last event must be a ButtonClick event. Other controls in the middle are irrelevant to the order of mouse clicks, but are related to the front and back positions of the controls. Because the content of the entire webpage is submitted to the server in the form of a form, the server cannot know the time sequence of the events you trigger, but can only know the events you trigger. Therefore, from page loading to submission, the intermediate control event is executed in order of location.
Here is the webpage running principle and event execution sequence ......