网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 大学论文导航 设计下载 最新论文 下载排行 原创论文 论文源代码
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > ASP.net > 正文

两个粒度看Asp.net生命周期

来源:http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/12
bsp;e)
48    {
49        Response.Write("Page_SaveStateComplete<br/>");
50
51    }
52
53   
54    protected void Page_Unload(object sender, EventArgs e)
55    {
56        int i = 0;
57        i++;//这行代码是用来设置断点的,为什么不用Response.Write?你说呢?
58
59    }
60
61
62    protected void Button1_Click(object sender, EventArgs e)
63    {
64        Label1.Text = "ControlEvent";
65        Response.Write("Button事件触发!<br/>");
66    }
67}
68
69
70
运行结果:
 

Page_PreInit

Page_Init

Page_InitComplete

Page_PreLoad

Page_Load

Page_LoadComplete

Page_PreRender

Page_SaveStateComplete


点击页面的Button后的输出:

Page_PreInit

Page_Init

Page_InitComplete

Page_PreLoad

Page_Load

Button事件触发!

Page_LoadComplete

Page_PreRender

Page_SaveStateComplete

 

我们从一个更细的粒度,在Reflector中看Page对请求处理的代码:
private void PerformPreInit()
{
           this.OnPreInit(EventArgs.Empty);
    this.InitializeThemes();//看到主题和模板页是什么时候加载了吧
    this.ApplyMasterPage();
    this._preInitWorkComplete = true;
}


MSDN上对Asp.net生命周期解释有非常重要的四个表格:

     

    Stage

    Description

    Page request

    The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.

    Start

    In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page''s UICulture property is set.

    Page initialization

    During page initialization, controls on the page are available and each control''s UniqueID property is set. Any themes are also applied to the page. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.

    Load

    During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.

    Validation

    During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.

    Postback event handling

    If the request is a postback, any event handlers are called.

    Rendering

    Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page''s Response property.

    Unload

    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.

网学推荐

免费论文

原创论文

设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号