日志不说谎--Asp.net的生命周期 【结题】

本文深入探讨了ASP.NET中Page.IsPostBack属性的工作原理,通过Reflector工具解析了该属性的源码,揭示了IsPostBack判断机制背后的两大关键因素:requestvaluecollection的存在与否及ViewState哈希值的一致性。
日志不说谎--Asp.net的生命周期
None.gif 这个问题解决掉了,要想知道为什么Page.IsPostBack为true,就要看看Asp.net中是怎么实现这个属性的;
None.gif打开Reflector,依次点开System.Web.UI.Page
None.gif
public bool get_IsPostBack()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
if(this._requestValueCollection!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if(this._isCrossPagePostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
returntrue;
ExpandedSubBlockEnd.gif}

InBlock.gif
if(this._pageFlags[8])
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
returnfalse;
ExpandedSubBlockEnd.gif}

InBlock.gif
if((this.Context.ServerExecuteDepth<=0)||((this.Context.Handler!=null)&&(base.GetType()==this.Context.Handler.GetType())))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
return!this._fPageLayoutChanged;
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gif
returnfalse;
ExpandedBlockEnd.gif}

None.gifIsPostBack由两个因素决定:
1 .requestvaluecollection(formpostcollection) if that ' smissingthenit ' snotpostbackstraightaway. 2 .detected if datacomingfromViewStatecontainssamehashcode as onpreviousrequest,that is if thehashcodedoesn ' tmatchthenitisnotapostback
None.gif

None.gif
None.gif
None.gif
坚强2002和你一起回头再说...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值