Before writing JSP, user input page is a page, processing user input is a page. Because of the stateless nature of HTTP we can only send the requested data to the server through get and post. But we don't need to enter data for the asp.net. Processing user data and write a separate page, we only need to double-click the Submit button, in the background to write the corresponding processing code can be, the user input data we can also like to write a Windows program as direct access.
I've been wondering how he did it. In particular, what IsPostBack (indicates whether it was the first time the page was accessed) This common attribute I don't know how it was set. Ruthless cruel in the internet looked for, ready to thoroughly understand it. Found an English article, I think it's good. Http://aspalliance.com/articleViewer.aspx?aId=134&pId. But my English proficiency is not able to translate, in here just to write down their own understanding, Let's just be a little bit of a kick. I also hope that the cow to give a good translation.
ASP.net page event execution order:
I. Initialization section:
1. Constructor: Creates an instance of the page class that initializes the properties of the page class.
2.AddParsedSubObject function:
protected virture void AddParsedSubObject (Object obj)
Extracts the server controls in the ASPX file and adds them to the page's ControlCollection. You can get all the server controls loaded by Page.controls
3.DeterminePostBackMode function:
Protected internal Virtual NameValueCollection DeterminePostBackMode ()
Return: NameValueCollection contains data sent by the user via Get or post, and returns empty if the first request is made. VIEWSTATE and Eventtarget These two hidden form fields will help us to determine whether this is the first request. After this event is invoked, the IsPostBack will be set.
4.OnInit function:
protected internal override void OnInit (EventArgs e)
Invokes the Init event, initializes all controls in the page to their default values (values you set in the ASPX page, viewstate values are not set to the control)
two. Non-initialization of the first request:
1.LoadPageStateFromPersistenceMedium function:
Protected internal Virtual Object LoadPageStateFromPersistenceMedium ()
Load viewstate information into the Page object (at which point the obtained value is not set to the corresponding control)
2.LoadViewState function:
protected virtual void LoadViewState (Object savedstate)
To re-establish viewstate information for a control
3.ProcessPostData function:
A private method that cannot be accessed
Gets the data entered by the user and maps them to the properties of the corresponding control
The properties of the controls that are used on this page are loaded, and the following is the appropriate event for you
Three. Event Processing Section
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, specifying the local variable properties. (which is the Page_Load event that we often write)
Four. Functions that are not required for the first request are used to invoke the various events you have written:
1.ProcessPostData: Call the Processpostdata function again primarily to handle the data information of the control that was dynamically created in the Page_Load event
2.RaiseChangedEvents: Responding to control property Change event
3.RaisePostBackEvent: Submit Event for Response button
Five. Handling OnPreRender Events:
The last chance to modify control properties before the page is passed to the browser
Six. The content on this page cannot be modified, so the next time the user's postback is ready for the condition and the corresponding HTML file is generated.
1.SaveViewState: Because the properties in the server control may have been changed in the event, we need to change the information into the ViewState
2.SavePageStateToPersistenceMedium: Save ViewState State information for the page, which is to save the Viewstat object obtained above to a hidden field or session
3.Render: Create an HTML file and send it to the browser
4.Unload: Release the corresponding resources, such as database connection, file handle, etc.
So much, the deficiencies also hope that everyone pointing. Learning Together is our goal