只有在◎Page指令中设置了:AutoEventWireup="true",服务器端的编译器将按照 Page_eventname 方法名的形式自动的检查相应事件处理方法,自动实现事件的订阅。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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
{
protected void Page_AbortTransaction()
{
Label1.Text += "<br />Page_AbortTransaction happened !";
}
protected void Page_CommitTransaction()
{
Label1.Text += "<br />Page_CommitTransaction happened !";
}
protected void Page_DataBinding()
{
Label1.Text += "<br />Page_DataBinding happened !";
}
protected void Page_Disposed()
{
Label1.Text += "<br />Page_Disposed happened !";
}
protected void Page_Error()
{
Label1.Text += "<br />Page_Error happened !";
}
protected void Page_Init()
{
Label1.Text += "<br />Page_Init happened !";
}
protected void Page_InitComplete()
{
Label1.Text += "<br />Page_InitComplete happened !";
}
protected void Page_Load()
{
Label1.Text += "<br />Page_Load happen !";
}
protected void Page_LoadComplete()
{
Label1.Text += "<br />Page_LoadComplete happened !";
}
protected void Page_PreInit()
{
Label1.Text += "<br />Page_PreInit happened !";
}
protected void Page_PreLoad()
{
Label1.Text += "<br />Page_PreLoad happened !";
}
protected void Page_PreRender()
{
Label1.Text += "<br />Page_PreReader happened !";
}
protected void Page_PreRenderComplete()
{
Label1.Text += "<br />Page_PreReaderComplete happened !";
}
protected void Page_SaveStateComplete()
{
Label1.Text += "<br />Page_SaveStateComplete happened !";
}
protected void Page_Unload()
{
Label1.Text += "<br />Page_Unload happened !";
}
}
执行顺序:
Page_PreInit happened !
Page_Init happened !
Page_InitComplete happened !
Page_PreLoad happened !
Page_Load happen !
Page_LoadComplete happened !
Page_PreReader happened !
Page_PreReaderComplete happened !
Page_SaveStateComplete happened !
当然关闭窗口的时候会有:Page_Unload happened !