This paper introduces the sequence of event execution in asp.net by means of actual combat.
Method/Step
Create a new C # WebForm project, as shown in the following illustration:
Add a button control in the Defualt.aspx file and name it Button1, and then add an event handler for each event for the control and add a breakpoint, as shown in the following figure:
Open the Global.asax file and add a breakpoint, as shown in the following figure:
Open the Site.master code file Site.Master.cs and add breakpoints, as shown in the following figure:
Press F5 to run, and view the sequence of code runs: Application_start→session_start→button1_init→page_load (defualt.asp) →page_ Load (site.master) →button1_load→button1_prerender→button1_unload→ display interface.
When we shut down IIS, we execute: session_end→application_end.
Summarize:
1. Execute the Application_Start function when you start the Web site through IIS, and execute the Application_End function when you close the Web site. These two functions can be thought of as being invoked by IIS.
2, when there is a new connection request to execute the Session_Start function, this time can use the session object, when the user does not operate for a long time, more than the session length, the implementation of the Session_End function. These two functions can also be thought of as IIS calls.
3. When requesting an ASPX page, the init function of all controls is executed first, then the Page_Load function of the page is executed, if there is a motherboard and then executes the Page_Load function of the motherboard, then executes the control's load function, PreRender function, unload function, The corresponding interface is displayed when all server controls have executed these functions.
Now we have a general understanding of how events in asp.net occur in turn, and hope to help you learn the sequence of events in asp.net.