Asp.net 页面生命周期:从OnPreInit到End Render
2013-07-25 09:53
190 查看
从下面的页面我们可以看到asp.net 的一个页面从创建到创建完成都执行了哪些操作以及他们的执行顺序。
![](http://img.blog.csdn.net/20130725095503937?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc21hcnRjbGllbnQxNjM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
/*
*/
代码如下:
//Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default"Trace="true" %>
//Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default : System.Web.UI.Page ,ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
Trace.Warn("Page_Load");
}
public override void ApplyStyleSheetSkin(Page page)
{
base.ApplyStyleSheetSkin(page);
Trace.Warn("ApplyStyleSheetSkin");
}
protected override HtmlTextWriter CreateHtmlTextWriter(System.IO.TextWriter tw)
{
Trace.Warn("CreateHtmlTextWiter");
return base.CreateHtmlTextWriter(tw);
}
protected override ControlCollection CreateControlCollection()
{
Trace.Warn("CreateControlCollection");
return base.CreateControlCollection();
}
protected override System.Collections.Specialized.NameValueCollection DeterminePostBackMode()
{
Trace.Warn("DeterminePostBackMode");
return base.DeterminePostBackMode();
}
protected override void InitializeCulture()
{
Trace.Warn("InitializeCulture");
base.InitializeCulture();
}
protected override void FrameworkInitialize()
{
Trace.Warn("FrameworkInitialize");
base.FrameworkInitialize();
}
protected override void InitOutputCache(int duration, string varyByHeader, string varyByCustom, OutputCacheLocation location, string varyByParam)
{
Trace.Warn("InitOutputCache");
base.InitOutputCache(duration, varyByHeader, varyByCustom, location, varyByParam);
}
protected override object LoadPageStateFromPersistenceMedium()
{
Trace.Warn("LoadPageStateFromPersistenceMedium");
return base.LoadPageStateFromPersistenceMedium();
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Trace.Warn("OnInit");
}
protected override void OnInitComplete(EventArgs e)
{
Trace.Warn("OnInitComplete");
base.OnInitComplete(e);
}
protected override void OnLoadComplete(EventArgs e)
{
Trace.Warn("OnLoadComplete");
base.OnLoadComplete(e);
}
protected override void OnPreInit(EventArgs e)
{
Trace.Warn("OnPreInit");
base.OnPreInit(e);
}
protected override void OnPreLoad(EventArgs e)
{
Trace.Warn("OnPreLoad");
base.OnPreLoad(e);
}
protected override void OnPreRenderComplete(EventArgs e)
{
Trace.Warn("OnPreRenderComplete");
base.OnPreRenderComplete(e);
}
protected override void OnSaveStateComplete(EventArgs e)
{
Trace.Warn("OnSaveStateComplete");
base.OnSaveStateComplete(e);
}
public override void ProcessRequest(HttpContext context)
{
Trace.Warn("ProcessRequest");
base.ProcessRequest(context);
}
protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
Trace.Warn("RaisePostBackEvent");
base.RaisePostBackEvent(sourceControl, eventArgument);
}
protected override void Render(HtmlTextWriter writer)
{
Trace.Warn("Render");
base.Render(writer);
}
protected override void SavePageStateToPersistenceMedium(object state)
{
Trace.Warn("SavePageStateToPersistenceMedium");
base.SavePageStateToPersistenceMedium(state);
}
#region ICallbackEventHandler 成员
public string GetCallbackResult()
{
throw new Exception("The method or operation is not implemented.");
}
public void RaiseCallbackEvent(string eventArgument)
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
/*
类别 | 消息 | From First(s) | From Last(s) |
---|---|---|---|
DeterminePostBackMode | |||
aspx.page | Begin PreInit | 0.000040 | 0.000040 |
OnPreInit | 0.000289 | 0.000249 | |
aspx.page | End PreInit | 0.000325 | 0.000036 |
aspx.page | Begin Init | 0.000338 | 0.000014 |
OnInit | 0.000483 | 0.000145 | |
aspx.page | End Init | 0.000509 | 0.000026 |
aspx.page | Begin InitComplete | 0.000522 | 0.000013 |
OnInitComplete | 0.000639 | 0.000116 | |
aspx.page | End InitComplete | 0.000663 | 0.000024 |
aspx.page | Begin PreLoad | 0.000680 | 0.000017 |
OnPreLoad | 0.000795 | 0.000115 | |
aspx.page | End PreLoad | 0.000818 | 0.000024 |
aspx.page | Begin Load | 0.000832 | 0.000013 |
Page_Load | 0.001144 | 0.000312 | |
aspx.page | End Load | 0.001183 | 0.000039 |
aspx.page | Begin LoadComplete | 0.001206 | 0.000023 |
OnLoadComplete | 0.001372 | 0.000166 | |
aspx.page | End LoadComplete | 0.001399 | 0.000027 |
aspx.page | Begin PreRender | 0.001412 | 0.000014 |
aspx.page | End PreRender | 0.001493 | 0.000081 |
aspx.page | Begin PreRenderComplete | 0.001517 | 0.000024 |
OnPreRenderComplete | 0.001642 | 0.000125 | |
aspx.page | End PreRenderComplete | 0.001666 | 0.000024 |
aspx.page | Begin SaveState | 0.001858 | 0.000192 |
SavePageStateToPersistenceMedium | 0.002551 | 0.000693 | |
aspx.page | End SaveState | 0.003602 | 0.001051 |
aspx.page | Begin SaveStateComplete | 0.003654 | 0.000051 |
OnSaveStateComplete | 0.003911 | 0.000257 | |
aspx.page | End SaveStateComplete | 0.082377 | 0.078466 |
aspx.page | Begin Render | 0.082457 | 0.000080 |
CreateHtmlTextWiter | 0.082774 | 0.000317 | |
Render | 0.083404 | 0.000630 | |
aspx.page | End Render | 0.083990 | 0.000586 |
CreateHtmlTextWiter | 0.084585 | 0.000595 |
代码如下:
//Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default"Trace="true" %>
//Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default : System.Web.UI.Page ,ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
Trace.Warn("Page_Load");
}
public override void ApplyStyleSheetSkin(Page page)
{
base.ApplyStyleSheetSkin(page);
Trace.Warn("ApplyStyleSheetSkin");
}
protected override HtmlTextWriter CreateHtmlTextWriter(System.IO.TextWriter tw)
{
Trace.Warn("CreateHtmlTextWiter");
return base.CreateHtmlTextWriter(tw);
}
protected override ControlCollection CreateControlCollection()
{
Trace.Warn("CreateControlCollection");
return base.CreateControlCollection();
}
protected override System.Collections.Specialized.NameValueCollection DeterminePostBackMode()
{
Trace.Warn("DeterminePostBackMode");
return base.DeterminePostBackMode();
}
protected override void InitializeCulture()
{
Trace.Warn("InitializeCulture");
base.InitializeCulture();
}
protected override void FrameworkInitialize()
{
Trace.Warn("FrameworkInitialize");
base.FrameworkInitialize();
}
protected override void InitOutputCache(int duration, string varyByHeader, string varyByCustom, OutputCacheLocation location, string varyByParam)
{
Trace.Warn("InitOutputCache");
base.InitOutputCache(duration, varyByHeader, varyByCustom, location, varyByParam);
}
protected override object LoadPageStateFromPersistenceMedium()
{
Trace.Warn("LoadPageStateFromPersistenceMedium");
return base.LoadPageStateFromPersistenceMedium();
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Trace.Warn("OnInit");
}
protected override void OnInitComplete(EventArgs e)
{
Trace.Warn("OnInitComplete");
base.OnInitComplete(e);
}
protected override void OnLoadComplete(EventArgs e)
{
Trace.Warn("OnLoadComplete");
base.OnLoadComplete(e);
}
protected override void OnPreInit(EventArgs e)
{
Trace.Warn("OnPreInit");
base.OnPreInit(e);
}
protected override void OnPreLoad(EventArgs e)
{
Trace.Warn("OnPreLoad");
base.OnPreLoad(e);
}
protected override void OnPreRenderComplete(EventArgs e)
{
Trace.Warn("OnPreRenderComplete");
base.OnPreRenderComplete(e);
}
protected override void OnSaveStateComplete(EventArgs e)
{
Trace.Warn("OnSaveStateComplete");
base.OnSaveStateComplete(e);
}
public override void ProcessRequest(HttpContext context)
{
Trace.Warn("ProcessRequest");
base.ProcessRequest(context);
}
protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
Trace.Warn("RaisePostBackEvent");
base.RaisePostBackEvent(sourceControl, eventArgument);
}
protected override void Render(HtmlTextWriter writer)
{
Trace.Warn("Render");
base.Render(writer);
}
protected override void SavePageStateToPersistenceMedium(object state)
{
Trace.Warn("SavePageStateToPersistenceMedium");
base.SavePageStateToPersistenceMedium(state);
}
#region ICallbackEventHandler 成员
public string GetCallbackResult()
{
throw new Exception("The method or operation is not implemented.");
}
public void RaiseCallbackEvent(string eventArgument)
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
相关文章推荐
- ASP.NET 应用程序页面生命周期概述。
- ASP.NET页面生命周期描述
- ASP.NET页面生命周期描述
- Asp.Net页面生命周期
- ASP.NET页面揭秘之页面生命周期
- ASP.NET页面生命周期
- 深入研究Asp.net页面的生命周期
- 最权威的 asp.net页面的生命周期
- asp.net页面生命周期
- NET (C#) Internals: ASP.NET 应用程序与页面生命周期(收藏)
- 在ASP.NET 2.0中,一个ASP.NET页面的生命周期
- [转]Asp.net页面的生命周期
- Asp.net页面的生命周期
- ASP.NET 页面生命周期
- Asp.net页面的生命周期
- Asp.net页面的生命周期
- Asp.net 页面生命周期
- ASP.NET页面生命周期描述
- ASP.NET应用程序与页面生命周期
- (英文翻译)Asp.net应用程序以及页面的生命周期