Page.IsPostBack Page.IsPostBack Page.IsPostBack Page.IsPostBack Property

定義

取得值,這個值表示網頁為初次呈現,或是要回應回傳而載入。Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback.

public:
 property bool IsPostBack { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool IsPostBack { get; }
member this.IsPostBack : bool
Public ReadOnly Property IsPostBack As Boolean

屬性值

如果回應用戶端回傳而載入則為 true,否則為 falsetrue if the page is being loaded in response to a client postback; otherwise, false.

範例

下列範例示範如何測試的值IsPostBack屬性以判斷頁面是否轉譯第一次,或回應回傳載入頁面時。The following example shows how to test the value of the IsPostBack property when the page is loaded in order to determine whether the page is being rendered for the first time or is responding to a postback. 如果在第一次呈現網頁,程式碼會呼叫Page.Validate方法。If the page is being rendered for the first time, the code calls the Page.Validate method.

(未顯示) 的頁面標記包含RequiredFieldValidator顯示星號,如果沒有項目對必要的輸入欄位的控制項。The page markup (not shown) contains RequiredFieldValidator controls that display asterisks if no entry is made for a required input field. 呼叫Page.Validate會導致立即頁面呈現的時間,而不是等待,直到使用者按一下 [提交] 按鈕要顯示的星號。Calling Page.Validate causes the asterisks to be displayed immediately when the page is rendered, instead of waiting until the user clicks the Submit button. 在回傳時之後, 您就不必呼叫Page.Validate,因為該方法呼叫的一部分Page生命週期。After a postback, you do not have to call Page.Validate, because that method is called as part of the Page life cycle.

private void Page_Load()
{
    if (!IsPostBack)
    {
        // Validate initially to force asterisks
        // to appear before the first roundtrip.
        Validate();
    }
}
Sub Page_Load
    If Not IsPostBack
        ' Validate initially to force the asterisks
        ' to appear before the first roundtrip.
        Validate()
    End If
End Sub

備註

如需回傳和回呼之間的差異的說明,請參閱 < 實作用戶端回呼而不需要回傳For an explanation of the difference between postbacks and callbacks, see Implementing Client Callbacks Without Postbacks.

適用於

另請參閱