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.

適用於

另請參閱