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


获取一个值,该值指示页验证是否成功。Gets a value indicating whether page validation succeeded.

 property bool IsValid { bool get(); };
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, 则TextlblOutput控件的属性将设置为 "Page 有效!"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)
    if (Page.IsValid == true)
        lblOutput.Text = "Page is Valid!";
        lblOutput.Text = "Some required fields are empty.";
Sub ValidateBtn_Click(sender As Object, e As EventArgs)
    If (Page.IsValid) Then
        lblOutput.Text = "Page is Valid!"
        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在调用方法后检查此属性, 或在启动窗体处理的 ASP.NET 服务器控件的OnServerClick事件处理程序中CausesValidation将属性设置为trueYou 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. 这些服务器控件包括ButtonHtmlButtonHtmlInputButton HtmlInputImage、、 ImageButton和类。LinkButtonThese 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.