Page.IsValid Property
Gets a value indicating whether page validation succeeded.
[Visual Basic] Public ReadOnly Property IsValid As Boolean [C#] public bool IsValid {get;} [C++] public: __property bool get_IsValid(); [JScript] public function get IsValid() : Boolean;
Property Value
true if page validation succeeded; otherwise, false.
Remarks
For this property to return true, all validation server controls in the Page.Validators property must validate successfully. You should check this property only after you have called the Page.Validate method, or set the CausesValidation property to true in the OnServerClick handler for an ASP.NET server control that initiates form processing. These server controls include the Button, HtmlButton, HtmlInputButton, HtmlInputImage, ImageButton, and LinkButton classes.
Example
[Visual Basic, C#, JScript] The following example demonstrates using the IsValid property to set up a conditional statement. 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".
[Visual Basic] Sub ValidateBtn_Click(sender As Object, e As EventArgs) If (Page.IsValid) Then lblOutput.Text = "Page is Valid!" Else lblOutput.Text = "Some of the required fields are empty" End If End Sub [C#] void ValidateBtn_Click(Object Sender, EventArgs E) { if (Page.IsValid == true) { lblOutput.Text = "Page is Valid!"; } else { lblOutput.Text = "Some of the required fields are empty"; } } [JScript] function ValidateBtn_Click(Sender, e : EventArgs) { if (Page.IsValid == true) { lblOutput.Text = "Page is Valid!"; } else { lblOutput.Text = "Some of the required fields are empty"; } }
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
Page Class | Page Members | System.Web.UI Namespace | Validators | ValidatorCollection