asp.net主要页面周期

新建页面pagecycle.aspx,页面代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pagecycle.aspx.cs" Inherits="MyWebSiteTest.pagecycle" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body{font-family:Fixedsys Excelsior 3.01,Arial,Verdana,宋体; }
        p{ font-size:16px;padding:8px 10px 8px 30px;
           position:relative; border:1px solid #FCDEA7; 
           background-color:#f8f8d8; color:#333; line-height:1.5em;  }
        .txt{ border:none; width:550px; background-color:#31363E; color:#Fff; }
    </style>
    <script  type="text/javascript">
    <!--
            function __doPostBack(eventTarget, eventArgument) {
                Form1.__EVENTTARGET.value = eventTarget.split("$").join(":");
                Form1.__EVENTARGUMENT.value = eventArgument;
                Form1.submit();
            }
    // -->
    </script>

</head>
<body>
    <form id="Form1" runat="server">
    <input type="hidden" name="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" value="" />
    <div>
       <p>
        <ul>
            <li>源代码 :<span><</span><span>asp:</span><span>LinkButton ID="lbtn"</span>
                    <span>runat="server" οnclick="lbtn_Click"></span><span>测试一下<</span><span>/asp:LinkButton></span></li>
            <li>
                html输出:<span><</span><span>a id="lbtn" href="javascript:__doPostBack('lbtn','')">模仿LinkButton回发事件<</span><span>/a></span>
            </li>
        </ul>
       </p>
       <%--<asp:LinkButton ID="lbtn" runat="server" οnclick="lbtn_Click">测试一下</asp:LinkButton>--%><br />
       <a id="lbtn" href="javascript:__doPostBack('lbtn','');">模仿LinkButton回发事件</a>
    </div>
    </form>
</body>
</html>

后台代码:

namespace MyWebSiteTest
{
    /// <summary>
    /// 页面生命周期测试
    /// </summary>
    public partial class pagecycle : System.Web.UI.Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            Response.Write("<p>Page_PreInit:在页初始化开始时发生</p>");
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            Response.Write("<p>Page_Init:当服务器控件初始化时发生;初始化是控件生存期的第一步</p>");
        }
        protected void Page_PreLoad(object sender, EventArgs e)
        {
            Response.Write("<p>Page_PreLoad:当页load事件<span style=\"color:#f00;\">之前</span>发生</p>");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                string target = Request.Form["__EVENTTARGET"] != null ? Request.Form["__EVENTTARGET"].ToString() : "";
                string args = Request.Form["__EVENTARGUMENT"] != null ? Request.Form["__EVENTARGUMENT"].ToString() : "";
                lbtn_Click(sender, e);
            }

            Response.Write("<p>Page_Load:这是Page_Load事件</p>");
        }
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            Response.Write("<p>Page_LoadComplete:当页初始化完成时发生</p>");
            Page_Disposed(sender, e);//显示调用
        }
        protected void Page_Disposed(object sender, EventArgs e)
        {
            //this.Page.Dispose();
            string str = "如不调用,则垃圾回收随机进行激发,垃圾回收是随机的不可知的(此处是显示的被Page_LoadComplete调用触发)";
            Response.Write("<p>Page_Disposed:页面从内存中卸载时发生<br/>" + str + "</p>");
        }

        protected void lbtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://www.baidu.com");
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值