日志不说谎--Asp.net的生命周期
这个问题解决掉了,要想知道为什么Page.IsPostBack为true,就要看看Asp.net中是怎么实现这个属性的;
打开Reflector,依次点开System.Web.UI.Page
public
bool
get_IsPostBack()

{
if(this._requestValueCollection!=null)


{
if(this._isCrossPagePostBack)


{
returntrue;
}
if(this._pageFlags[8])


{
returnfalse;
}
if((this.Context.ServerExecuteDepth<=0)||((this.Context.Handler!=null)&&(base.GetType()==this.Context.Handler.GetType())))


{
return!this._fPageLayoutChanged;
}
}
returnfalse;
}
IsPostBack由两个因素决定:
1
.requestvaluecollection(formpostcollection)
if
that
'
smissingthenit
'
snotpostbackstraightaway.
2
.detected
if
datacomingfromViewStatecontainssamehashcode
as
onpreviousrequest,that
is
if
thehashcodedoesn
'
tmatchthenitisnotapostback


这个问题解决掉了,要想知道为什么Page.IsPostBack为true,就要看看Asp.net中是怎么实现这个属性的;
打开Reflector,依次点开System.Web.UI.Page
public
bool
get_IsPostBack()
{
if(this._requestValueCollection!=null)

{
if(this._isCrossPagePostBack)

{
returntrue;
}
if(this._pageFlags[8])

{
returnfalse;
}
if((this.Context.ServerExecuteDepth<=0)||((this.Context.Handler!=null)&&(base.GetType()==this.Context.Handler.GetType())))

{
return!this._fPageLayoutChanged;
}
}
returnfalse;
}
IsPostBack由两个因素决定:
1
.requestvaluecollection(formpostcollection)
if
that
'
smissingthenit
'
snotpostbackstraightaway.
2
.detected
if
datacomingfromViewStatecontainssamehashcode
as
onpreviousrequest,that
is
if
thehashcodedoesn
'
tmatchthenitisnotapostback


本文深入探讨了ASP.NET中Page.IsPostBack属性的工作原理,通过Reflector工具解析了该属性的源码,揭示了IsPostBack判断机制背后的两大关键因素:requestvaluecollection的存在与否及ViewState哈希值的一致性。
629

被折叠的 条评论
为什么被折叠?



