返回列表 回复 发帖

关于窗体页事件顺序测试的问题

------------------------测试窗体页事件顺序,代码如下-------------------------

protected void Page_PreInit(object sender,EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_PreInit";
        Response.Write(s);
        Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }
    /// <summary>
    /// 窗体页初始化
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Init(object sender,EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_Init";
        Response.Write(s);
        Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }
    /// <summary>
    /// 窗体页初始化完成
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_InitComplete(object sender, EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_InitComplete";
        Response.Write(s);
        Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }
    /// <summary>
    /// 窗体页预加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_PreLoad(object sender, EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_PreLoad";
        Response.Write(s);
        Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }
    /// <summary>
    /// 窗体页加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_Load";
        Response.Write(s);
        Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }
    /// <summary>
    /// 窗体页加载完成
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_LoadComplete";
        Response.Write(s);
        Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }
    /// <summary>
    /// 窗体页渲染前
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_PreRender(object sender, EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_PreRender";
        Response.Write(s);
        Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }
    /// <summary>
    ///窗体页保存视图状态
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_SaveStateComplete(object sender, EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_SaveStateComplete";
        Response.Write(s);
        Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }
    /// <summary>
    /// 窗体页渲染
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Render(object sender, EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_Render";
        Response.Write(s);
        Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }
    /// <summary>
    /// 窗体页卸载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Unload(object sender, EventArgs e)
    {
        string s = DateTime.Now.ToLongTimeString();
        s += "事件名称为Page_Unload";
        ApplicationInstance.Response.Write(s);
        ApplicationInstance.Response.Write("<br />");
        System.Threading.Thread.Sleep(1000);
    }

------------------------输出结果如下-------------------------
20:56:29事件名称为Page_PreInit
20:56:30事件名称为Page_Init
20:56:31事件名称为Page_InitComplete
20:56:32事件名称为Page_PreLoad
20:56:33事件名称为Page_Load
20:56:34事件名称为Page_LoadComplete
20:56:35事件名称为Page_PreRender
20:56:36事件名称为Page_SaveStateComplete


20:56:37事件名称为Page_Unload
注意上面空一行,为Page_Render事件没有显示。请问为什么?
谢谢老师指点 还是有点没听明白 。“不过,如果自定义控件只合并标准的 ASP.NET Web 服务器控件,不合并自定义标记,则不需要重写 Render 方法。

”这一段不明白
谢谢老师的解答,依然坚持在看《ASP.NET从入门到实践》,不得不说,这是一本很适合新手学习的书。现在在看实例章节了,比这个问题提问的时候,又有多了新的认知,感谢您一直以来不厌其烦对我的帮助,谢谢。
返回列表