What events are fired as part of the ASP.NET System.Web.UI.Page lifecycle?
2014-07-25 01:46
676 查看
Reference: http://www.justinrhinesmith.com/blog/2008/05/04/what-events-are-fired-as-part-of-the-aspnet-systemwebuipage-lifecycle/ 这个博客里有三篇自己写的.NET理解,可以看。
http://msdn.microsoft.com/en-us/library/ms972976.aspx 这个配有例子,理解透彻。
Figure 1. ASP.NET Page Handling
Figure 2. Events in the Page Life Cycle
Figure
4. Events and View State
Question
From constructor to destructor (taking into consideration Dispose() and the concept of non-deterministic finalization), what events are fired as part of the ASP.NET System.Web.UI.Page lifecycle. Why are they important? What interesting things can you do at
each?
Answer
1. PreInit Event
Called at the very beginning of page initialization, this event has several practical uses in your code behind pages. A few of these uses are: Checking the IsPostBack property, dynamically setting a master page or theme property, dynamically creating controls,
and reading or setting property values. If you were so inclined, you could set a master page dynamically in the PreInit event as such:
2. Init Event
Called after the PreInit event and after all controls have been initialized and any skin settings have been applied, this event is very useful for initializing control properties before the page loads.
3. InitComplete Event
Like the name implies, this event is called after the Init event is completed. I’m at a bit of a loss for thinking up useful and/or interesting things to do with this event, but if there were any tasks that needed to be completed once the controls were initialized,
this would be the place to do it.
4. PreLoad Event
This event is called immediately before the Page.Load event and after all postback data has been processed.
5. Load Event
Probably the most familiar since it comes for free whenever you switch to the code-behind (or hit F7) on an aspx page in Visual Studio. This event is useful for setting control properties and establishing database connections (both of which could be used to
populate a drop-down from the database, for example).
6. LoadComplete Event
What else could possibly follow up the Load event? This event is useful for doing any processing that requires that all controls on the page first be loaded.
7. PreRender Event
This event is useful for making any final changes to the page or the controls before the output is rendered to the browser.
8. PreRenderComplete Event
Called after PreRender is completed. This is the last event to be called before the viewstate is saved.
9. SaveStateComplete Event
Called once the viewstate has been saved. Use this for any processing that requires the viewstate to be saved but that doesn’t affect the rendering of the controls.
10. Render
While not technically an event, this method gets called for every control on the page. When creating a custom control (that requires custom markup), you could override this method to provide your own markup.
11. Unload Event
Use this event to do any final cleanup work on the page. Any controls on the page will also have an unload event that can be used to do cleanup on the controls themselves.
12. Disposed Event
This is the last event called for a control when it is released from memory on the server. The is the last stage of the ASP.NET lifecycle when a page is requested.
http://msdn.microsoft.com/en-us/library/ms972976.aspx 这个配有例子,理解透彻。
Figure 1. ASP.NET Page Handling
Figure 2. Events in the Page Life Cycle
Figure
4. Events and View State
Question
From constructor to destructor (taking into consideration Dispose() and the concept of non-deterministic finalization), what events are fired as part of the ASP.NET System.Web.UI.Page lifecycle. Why are they important? What interesting things can you do at
each?
Answer
1. PreInit Event
Called at the very beginning of page initialization, this event has several practical uses in your code behind pages. A few of these uses are: Checking the IsPostBack property, dynamically setting a master page or theme property, dynamically creating controls,
and reading or setting property values. If you were so inclined, you could set a master page dynamically in the PreInit event as such:
2. Init Event
Called after the PreInit event and after all controls have been initialized and any skin settings have been applied, this event is very useful for initializing control properties before the page loads.
3. InitComplete Event
Like the name implies, this event is called after the Init event is completed. I’m at a bit of a loss for thinking up useful and/or interesting things to do with this event, but if there were any tasks that needed to be completed once the controls were initialized,
this would be the place to do it.
4. PreLoad Event
This event is called immediately before the Page.Load event and after all postback data has been processed.
5. Load Event
Probably the most familiar since it comes for free whenever you switch to the code-behind (or hit F7) on an aspx page in Visual Studio. This event is useful for setting control properties and establishing database connections (both of which could be used to
populate a drop-down from the database, for example).
6. LoadComplete Event
What else could possibly follow up the Load event? This event is useful for doing any processing that requires that all controls on the page first be loaded.
7. PreRender Event
This event is useful for making any final changes to the page or the controls before the output is rendered to the browser.
8. PreRenderComplete Event
Called after PreRender is completed. This is the last event to be called before the viewstate is saved.
9. SaveStateComplete Event
Called once the viewstate has been saved. Use this for any processing that requires the viewstate to be saved but that doesn’t affect the rendering of the controls.
10. Render
While not technically an event, this method gets called for every control on the page. When creating a custom control (that requires custom markup), you could override this method to provide your own markup.
11. Unload Event
Use this event to do any final cleanup work on the page. Any controls on the page will also have an unload event that can be used to do cleanup on the controls themselves.
12. Disposed Event
This is the last event called for a control when it is released from memory on the server. The is the last stage of the ASP.NET lifecycle when a page is requested.
相关文章推荐
- Life Cycle Stages of ASP.NET Web Page.
- ASP.Net MVC – What are the uses of Display, DisplayName, DisplayFormat and ScaffoldColumn attributes
- What are the phases of the maven default lifecycle?
- What are the phases of the maven default lifecycle?
- ASP.NET(C#)——不扩展System.Web.UI.Page
- ASP.NET App_Code中的类文件如何继承System.Web.UI.Page
- asp.net报出“非静态字段、方法或属性’System.Web.UI.Page.Response.get‘要求对象引用”错误
- ASP.NET Page Events Lifecycle
- The ASP.NET Page Life Cycle
- Asp.Net 继承System.Web.UI.Page实现权限检测
- The ASP.NET Page Lifecycle
- asp.net web forms page life cycle
- Explain the page life cycle in ASP.NET 2.0
- ASP.Net MVC – What are the uses of Display, DisplayName, DisplayFormat and ScaffoldColumn attributes
- The ASP.NET Page Lifecycle – A Basic Approach
- [ASP.NET] ASP.NET web page Lifecycle
- asp.net “非静态字段、方法或属性’System.Web.UI.Page.Response.get‘要求对象引用”
- Complete Lifecycle of an ASP.Net page and controls
- ASP.NET HttpApplication HttpModule + Page Life Cycle Events Sequence Test
- ASP.NET中System.Web.UI.Page的继承问题