You do not have to use the validation control to output a response when the validator or page IsValid property is false. 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.
To display custom validation messages
-
In the Page_Load event handler, call the Validate method of the validation control or of the page.
-
Check the IsValid property of the validation control or page and conditionally add text or a control, or change the properties (for example, color) of a control.
The following code example displays the text "All entries are valid" when the IsValid property is true, and the text "There are one or more invalid entries" when the property is false.
Visual BasicВ Copy Code
If (Me.IsPostBack) Then ValidationControl1.Validate() If (ValidationControl1.IsValid) Then lblOutput.Text = "All entries are valid." Else lblOutput.Text = "There are one or more invalid entries." End If End If
C#В Copy Code
if (this.IsPostBack) { ValidationControl1.Validate(); if (ValidationControl1.IsValid) { lblOutput.Text = "All entries are valid."; } else { lblOutput.Text = "There are one or more invalid entries."; } }