Site sponsored by: Idera Try Idera’s new SQL admin toolset
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share you SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

Database Recovery Models in SQL Server
Compare Dates
Filtered Indexes in SQL Server 2008
Importance of Database Backups and Recovery Plan

More     
 
Latest FAQ's

ALTER TABLE SWITCH statement failed because the object '%.*ls' is not ...
ALTER TABLE SWITCH statement failed because column '%.*ls' at ordinal %d ...
ALTER TABLE SWITCH statement failed because table '%.*ls' has %d columns ...
SQL Server Reporting Server (SSRS) service is failing to start ...

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> asp.net / ado.net >> Understanding the Page Life Cycle in ASP.NET ...

Understanding the Page Life Cycle in ASP.NET

By : Joydip Kanjilal
May 01, 2007

Page 2 / 2

The Pre_Render event is triggered next and you can perform any update operations that you require prior to saving the View State and rendering of the web page content. You can perform the update operations on the ready-to-be rendered output in the PreRender event. Use the Pre_Render event to make any last minute changes to the contents of the web page or any of its controls.

The following code snippet illustrates how you can override the OnPreRender() method.

protected override void OnPreRender (EventArgs e)
{
  Page.Trace.Write ("The OnPreRender has been called.");
  //Any custom code
  base.OnPreRender(e);    
}

The SaveViewState that is called next saves the View State for the web page and its controls in the hidden field called __viewstate that is associated with every web page. Note that the SaveViewMethod that is associated with the SaveViewState event returns a null reference if there is no view state associated with the control. Refer to the code snippet below that illustrates how you can override the SaveViewState() method.

protected override object SaveViewState ()
{
  Page.Trace.Write ("The SaveViewState method has been called.");
  //Write your custom code here.
  return base.SaveViewState();
}

The rendering event is the next stage in the web page life cycle. This actually is not an event. Rather, it is a state of processing where the Page instance executes this method on all the controls of the web page to eventually render the web page content to the web browser at the client or the requestor side. It makes use of “a text writer that writes its output to the OutputStream of the page's Response property.” However, it should be noted that prior to rendering the web page, the view state for the web page and all its controls (provided view state for the web page and/or its controls enabled) are saved. You can trap the rendered output and make any changes on it, i.e., adding headers and footers to the rendered page, etc.

The last stage in the ASP.NET web page life cycle is the Page_UnLoad event. This event is called prior to the disposal of the web page and usually contains the code that is responsible for releasing of resources that were acquired in the earlier stages of the page life cycle. Once this is done, the web browser receives the “HTTP response packet” and the web page is displayed in the web browser. In this method, you can perform typical cleanup activities. According to MSDN, "Unload is called after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and any cleanup is performed." It should be noted that you cannot make any changes to the response stream in this event as the page and its controls have already been rendered.

The web browser now receives the HTTP response packet and displays the same in the web page. This concludes the page life cycle of an ASP.NET web page.

References

Please refer to the following links for related references on this topic.

http://msdn2.microsoft.com/en-us/library/ms178472.aspx

http://msdn2.microsoft.com/en-us/library/ms178473.aspx

http://www.15seconds.com/issue/020102.htm

http://www.aspfree.com/c/a/ASP.NET/ASP.NET-Life-Cycle-and-Best-Practices/

Conclusion

This article has had a detailed look at the series of steps that are involved in the page life cycle for an ASP.NET web page. I hope that the readers would find this article useful and I would welcome their comments and suggestions in this regard.


<< Prev Page         








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved