ASP.Net WebForm:表单提交时IsPostBack属性如何变为true

时间:2017-06-29 11:45:48

标签: webforms

请参阅此代码

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {

    }
}

我只想知道当表单提交只需单击提交按钮时,IsPostBack属性是谁以及如何变为true。谁将IsPostBack属性设置为true?

如果有人知道,请分享信息。

1 个答案:

答案 0 :(得分:1)

它是由System.Web dll中的ASP.NET框架控制的属性 - 特别是在System.Web.UI.Page类中。

/// <summary>Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback.</summary>
/// <returns>true if the page is being loaded in response to a client postback; otherwise, false.</returns>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsPostBack
{
    get
    {
        if (this._requestValueCollection == null)
        {
            return false;
        }
        if (this._isCrossPagePostBack)
        {
            return true;
        }
        if (this._pageFlags[8])
        {
            return false;
        }
        if (this.ViewStateMacValidationErrorWasSuppressed)
        {
            return false;
        }
        if (this.Context.ServerExecuteDepth > 0 && (this.Context.Handler == null || base.GetType() != this.Context.Handler.GetType()))
        {
            return false;
        }
        return !this._fPageLayoutChanged;
    }
}