ASP.NET Web Forms Web Forms Server Controls Web Forms Validation
In certain cases, you may not want or need to use the error message display of the validation control to output a response when validation fails. On both the client and server side, you can create a custom response, such as a color change in a control or a font change for text on a label.
- In the Page_Load event handler, call the control’s Validate method, then check the page’s IsValid property and conditionally add text to another control, such as a Label control, or change the properties ( for example, color ) of a control.
The following example displays the label "All entries are valid" when the IsValid property is true, and "There are one or more invalid entries" when the property is false.
myValidatorControl.Validate ( );
if ( this.IsValid ) {
lblOutput.Text = "All entries are valid.";
}
else {
lblOutput.Text = "There are one or more invalid entries.";
}
myValidatorControl.Validate ( )
If ( Me.IsValid ) Then
lblOutput.Text = "All entries are valid."
Else
lblOutput.Text = "There are one or more invalid entries."
End If |
|
C# |
VB |
Controlling Validation Message Display Formatting Validation Error Messages Specifying Error Mesage Layout Data Entry Validation ( Client-Side )