ASP.NET programming model of ASP.NET page life cycle What are they? What does it include? Programming model of ASP.NET ASP.NET page life cycle specific process, what does? Here we begin to explain it: ASP.NET page runs, the page will go through a life cycle, a series of processing steps in the life cycle. These steps include initialization, instantiating controls, to restore and maintain the state, running event handler code, and rendering. Understand the page life cycle is very important, so that we can write code in the appropriate stage of the life cycle, in order to achieve the desired results. In addition, if you develop a custom control, you must be familiar with the page life cycle, so as to properly initialize the controls, the use of view state data to populate control properties and behavior logic operation of all controls. Page ASP.NET programming model of the life cycle of a series of steps: page initialization, instantiating controls, to restore and maintain the state, running event handler code to display. In order to perform the necessary code at the appropriate stage, so be very familiar with the page life cycle. At all stages of the life cycle of the page, the page-by-defined trigger event, by executing the program we need in life event page in the development of the code 1, ASP.NET page life cycle of page requests: occurs before the page life cycle, when the user requests a page, ASP.NET will determine the need for analysis and compilation pages to determine whether to start the life cycle of the page, or if you can not send page cache to respond in the case of running page. 2, the beginning of the life cycle of an ASP.NET page: Set the page properties, such as: HttpContext and other properties; at this stage, to determine the required page is postback request or a new request and set IsPostBack property; UICulture property settings page. 3, page ASP.NET page life cycle of initialization: Load all subjects; the controls generation and set UniqueID; Note: ViewState, the value has not yet been loaded into ControlState in control; if the page is a postback, the postback data have not been loaded; it controls can be accessed at this time, but the value may be wrong. 4, load the ASP.NET page life cycle: if the current request is a postback request, for the control loads ViewState value and ControlState in. 5, ASP.NET page lifecycle of authentication: calling all validator controls the Validate method, which sets the IsValid property validator controls and pages. 6, postback events ASP.NET page life cycle of the process: If the request is a postback request, all event handler is called. 7, ASP.NET page life cycle of presentation: First of all controls on the page and save the view state, and then call the Render method for each control, it will provide a text writer, writes for the input controls page OutputStream Response property. 8, ASP.NET page life cycle of unloading: finish rendering, and has been sent to the client page, ready to discard the page after the call to unload. The uninstall attributes such as: Response and Request, and so on. Here is the ASP.NET programming model of ASP.NET page life cycle diagram The following is the initial page ASP.NET process: 下面对其中的一些过程作下描述: 对应的事件Page.Init 2. Load ViewState 没有对应的事件 3.Load Postback data; //每次这里的都回执行CODE HERE 对应的事件Page.Load 5. Handle control events; 没有对应的事件(我们自己的事件函数都包括在这个过程里比如上面的ListBox1_SelectedIndexChanged) 6. Page_ 对应的事件时Page.PreRender 7. Page_Render(); 对应的事件Page.Render 8. Unload event; 对应的事件Page.Unload 9. Dispose method called; 对应的事件Dispose 以上就是ASP.NET页面周期的描述。 注意上面灰色背景的文字,如果一个过程中有对应的事件,我们可以自己定义一个函数(当然先在MSDN中找到函数原型),然后在 Several processes for no corresponding event, such as 2.Load ViewState, we can override Page virtual function the override void the LoadViewState protected (Object savedState); add their own control codes, but should not fall with the corresponding base class, such as : |
Reproduced in: https: //www.cnblogs.com/Tim_Liu/archive/2011/04/26/2029507.html