IsPostback在技术上如何工作?

| 我目前遇到一个奇怪的问题,当我单击仅发布回同一页面的asp.net按钮时,除Google Chrome浏览器以外的所有浏览器都将Page_Load事件中的IsPostback调用注册为true。 这促使我尝试发现ASP.Net页面中IsPostback属性是如何实现的,这是我一直在努力寻找的问题。 到目前为止,我的想法是它可能与以下内容有关; 请求的VERB类型是POST而不是GET。 包含Viewstate信息的隐藏输入不存在任何信息,因此以前提交的控制信息不可用。 请求标头中的http引用网址与当前URL相同。 谁能提供用于确定IsPostback布尔属性的条件的实际细分? 注意:我正在寻找实际的实现方式,而不是感知/理论,因为我希望以此来积极解决问题。我还搜索了MSDN,到目前为止,找不到任何准确介绍该机制的技术文章。 提前致谢, 布莱恩     
已邀请:
该页面查找是否存在“ 0”形式的值。 从反射器:
public bool IsPostBack
{
    get
    {   //_requestValueCollection = Form or Querystring name/value pairs
        if (this._requestValueCollection == null)
        {
            return false;
        }

        //_isCrossPagePostBack = _requestValueCollection[\"__PREVIOUSPAGE\"] != null
        if (this._isCrossPagePostBack)
        {
            return true;
        }

        //_pageFlags[8] = this._requestValueCollection[\"__PREVIOUSPAGE\"] == null
        if (this._pageFlags[8])
        {
            return false;
        }

        return (   ((this.Context.ServerExecuteDepth <= 0) 
                || (   (this.Context.Handler != null) 
                    && !(base.GetType() != this.Context.Handler.GetType())))
                && !this._fPageLayoutChanged);
    }
}
    
回发实际上很简单,只需将表单提交给自己即可(大部分情况下)。 javascript代码实际上放在您的页面上:
<input type=\"hidden\" name=\"__EVENTTARGET\" id=\"__EVENTTARGET\" value=\"\" />
<input type=\"hidden\" name=\"__EVENTARGUMENT\" id=\"__EVENTARGUMENT\" value=\"\" />

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
标记答案将向您显示正在运行的服务器端代码。     
是否按以下方式实现回发(使用Reflector):
public bool get_IsPostBack()
{
    if (this._requestValueCollection == null)
    {
        return false;
    }
    if (this._isCrossPagePostBack)
    {
        return true;
    }
    if (this._pageFlags[8])
    {
        return false;
    }
    return (((this.Context.ServerExecuteDepth <= 0) || ((this.Context.Handler != null) && !(base.GetType() != this.Context.Handler.GetType()))) && !this._fPageLayoutChanged);
}
因此,除非您考虑所有这些参数,否则将无法对其进行跟踪。     

要回复问题请先登录注册