Page.IsValid Page.IsValid Page.IsValid Page.IsValid Property

定義

取得值,指出網頁驗證是否成功。Gets a value indicating whether page validation succeeded.

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

屬性值

如果網頁驗證成功則為 true,否則為 falsetrue if page validation succeeded; otherwise, false.

例外狀況

IsValid 屬性會在驗證發生之前呼叫。The IsValid property is called before validation has occurred.

範例

下列程式碼範例示範如何使用IsValid條件陳述式所設定的屬性。The following code example demonstrates using the IsValid property to set up a conditional statement. 如果屬性傳回true,則Text屬性lblOutput控制項設定為 「 頁面 」 有效 !If the property returns true, the Text property of the lblOutput control is set to "Page is valid!" 否則,它會設定為 「 一些必要的欄位是空的。 」Otherwise, it is set to "Some of the required fields are empty."

private void ValidateBtn_Click(Object Sender, EventArgs E)
{
    Page.Validate();
    if (Page.IsValid == true)
        lblOutput.Text = "Page is Valid!";
    else
        lblOutput.Text = "Some required fields are empty.";
}
Sub ValidateBtn_Click(sender As Object, e As EventArgs)
    Page.Validate()
    If (Page.IsValid) Then
        lblOutput.Text = "Page is Valid!"
    Else
        lblOutput.Text = "Some required fields are empty."
    End If
End Sub

備註

這個屬性傳回true,目前的驗證群組中的所有驗證伺服器控制項必須順利通過都驗證。For this property to return true, all validation server controls in the current validation group must validate successfully. 您應該檢查這個屬性,只有在您呼叫之後,才Page.Validate方法或一組CausesValidation屬性設trueOnServerClick起始表單處理 ASP.NET 伺服器控制項的事件處理常式。You should check this property only after you have called the Page.Validate method, or set the CausesValidation property to true in the OnServerClick event handler for an ASP.NET server control that initiates form processing. 這些伺服器控制項包括ButtonHtmlButtonHtmlInputButtonHtmlInputImageImageButton,和LinkButton類別。These server controls include the Button, HtmlButton, HtmlInputButton, HtmlInputImage, ImageButton, and LinkButton classes.

如果您強制驗證的驗證群組使用Validate方法,則指定的驗證群組中的所有驗證控制項必須順利通過驗證也。If you force validation of a validation group using the Validate method, then all validation controls in the specified validation group must validate successfully as well.

適用於

另請參閱