ASP.NET Page function call order resolution

  • 2020-05-10 17:57:55
  • OfStack

1. Initialization part:
1. Constructor: creates an instance of the page class and initializes the properties of the page class.
2. AddParsedSubObject function:
protected virture void AddParsedSubObject(Object obj)
Extract the server controls from the aspx file and add them to page's ControlCollection. You can get all the server controls loaded from Page.Controls
3. DeterminePostBackMode function:
protected internal virtual NameValueCollection DeterminePostBackMode ()
Return :NameValueCollection contains the data sent by the user via get or post. If it is the first request, it will return null.VIEWSTATE and EVENTTARGET, two hidden form fields, will help us determine if it is the first request. ispostback's will be set after this event is called.
4. OnInit function:
protected internal override void OnInit (EventArgs e)
Call the init event and initialize all controls in page to their default values (the values you set in the aspx page, the viewstate median will not be set to the control at this point)
2. Not initializing the carry 1 of the first request:
1. LoadPageStateFromPersistenceMedium function:
protected internal virtual Object LoadPageStateFromPersistenceMedium ()
Load the viewstate information into the page object (at this point, the value obtained is not set to the corresponding control)
2. LoadViewState function:
protected virtual void LoadViewState (Object savedState)
Re-establish the viewstate information for the control
3. ProcessPostData function:
1 private method, cannot be accessed
Takes the data entered by the user and maps it to the properties of the corresponding control

// now that the properties of the controls used on the page have been loaded, it's time to respond to your events
3. Event handling
1.OnLoad:
protected internal virtual void OnLoad (EventArgs e)
Call the page_load method to specify the page information, such as executing a database query, and specify the local variable property (the Page_load event).

4. Request the function to be executed for the first time to call the events you wrote:
1.ProcessPostData: call the ProcessPostData function again mainly to handle the data information of the control dynamically created in the Page_Load event
2.RaiseChangedEvents: response to control property change event
3.RaisePostBackEvent: submit event in response to button

5. Handling OnPreRender event:
Last chance to modify control properties before the page is passed to the browser

6. Now that the content of the page cannot be modified, it is time to prepare the conditions and generate the corresponding html file for the next user's postback
1.SaveViewState: since the properties in the server control may have been changed in the event, we need to change the information to viewstate
2.SavePageStateToPersistenceMedium: save the viewstate status information for the page, that is, save the viewstat object obtained above into the hidden field or session
3.Render: create the html file and send it to the browser
4.Unload: release corresponding resources, such as database connection, file handle, etc


Related articles: