這個問題解決掉了,要想知道為什麼Page.IsPostBack為true,就要看看Asp.net中是怎麼實作這個屬性的;
打開Reflector,依次點開System.Web.UI.Page
public bool get_IsPostBack()
{
if (this._requestValueCollection != null)
{
if (this._isCrossPagePostBack)
{
return true;
}
if (this._pageFlags[8])
return false;
if ((this.Context.ServerExecuteDepth <= 0) || ((this.Context.Handler != null) && (base.GetType() == this.Context.Handler.GetType())))
return !this._fPageLayoutChanged;
}
return false;
}
IsPostBack由兩個因素決定:1.request value collection (form post collection) if that's missing then it's not postback straight away. 2.detected if data coming from ViewState contains same hash code as on previous request ,that is if the hash code doesn't match then it is not a postback