Page.IsValid 属性

定义

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

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

属性值

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 将设置为 "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)
{
    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. 这些服务器控件包括 ButtonHtmlButton 、、 HtmlInputButton HtmlInputImageImageButtonLinkButton 类。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.

适用于

另请参阅