探Button控件的Click事件发生始末

先贴结果图:

点击后:

页面代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
		<hr />
		<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
	</div>
	</form>
</body>
</html>

  

public partial class _Default : System.Web.UI.Page
{
	Stopwatch watch = new Stopwatch();
	public _Default()
	{
		watch.Start();
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_PreInit<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_PreInit<br/>";
	}
	protected void Page_Init(object sender, EventArgs e)
	{
		//System.Threading.Thread.Sleep(1000);
		Response.Write(watch.ElapsedTicks + ": Page_Init<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_Init<br/>";
	}
	protected void Page_InitComplete(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_InitComplete<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_InitComplete<br/>";
	}
	protected void Page_PreLoad(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_PreLoad<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_PreLoad<br/>";
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_Load<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_Load<br/>";
	}
	protected void Page_LoadComplete(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_LoadComplete<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_LoadComplete<br/>";
	}
	protected void Page_PreRender(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_PreRender<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_PreRender<br/>";
	}
	protected void Page_PreRenderComplete(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_PreRenderComplete<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_PreRenderComplete<br/>";
	}
	protected void Page_SaveState(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_SaveState<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_SaveState<br/>";
	}
	protected void Page_SaveStateComplete(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_SaveStateComplete<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_SaveStateComplete<br/>";
	}
	protected void Page_Render(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Page_Render<br/>");
		Label1.Text += watch.ElapsedTicks + ": Page_Render<br/>";
	}

	protected void Button1_Click(object sender, EventArgs e)
	{
		Response.Write(watch.ElapsedTicks + ": Button1_Click<br/>");
		Label1.Text += watch.ElapsedTicks + ": Button1_Click<br/>";
	}
}

MSDN: ASP.NET 页生命周期概述

posted @ 2012-04-29 23:26  客家岸田  阅读(310)  评论(0编辑  收藏  举报
联系和建议: antield[at]126.com