asp.net.ph

Skip Navigation Links

Displaying Custom Error Messages

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.

To display custom validation messages

  • 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.";
}
  C# VB
See Also

Controlling Validation Message Display   Formatting Validation Error Messages   Specifying Error Mesage Layout   Data Entry Validation ( Client-Side )



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note