Name
IsValid
Synopsis
Boolean = Page.IsValid
Returns a Boolean value, indicating whether any validation controls on the page were unable to successfully validate user input.
Parameters
-
Boolean A Boolean indicating whether the validation succeeded.
Example
The example uses the IsValid property to determine whether validation on the current page succeeded, and displays a message:
<%@ Page Language="vb" %>
<html>
<head>
<title></title>
<script runat="server">
Sub Page_Load( )
If IsPostBack Then
Page.Validate( )
If Page.IsValid Then
Message.Text = "Page is valid."
Else
Message.Text = "Page is not valid."
End If
End If
End Sub
</script>
</head>
<body>
<form runat="server">
Enter your name:
<asp:textbox id="name" runat="server"/>
<asp:requiredfieldvalidator
id="rfvName"
controltovalidate="name"
enableclientscript="false"
errormessage="Required!"
runat="server"/>
<br/>
<asp:button id="submit" Text="Submit" runat="server"/>
<br/>
<asp:label id="Message" runat="server"/>
</form>
</body>
</html>Notes
The IsValid property determines whether the overall validation
performed by a form’s validator controls has
succeeded. If the page has no validator controls, the
property’s value is always True.
Before checking the value of IsValid, you must either call the
Page.Validate method, as shown in the example, or have submitted the
page with a control (such as a Button, ImageButton, or LinkButton
control) whose CausesValidation property is set to
True. Otherwise, an exception will occur.
In the example, the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access