asp.net.ph

Skip Navigation Links

Formatting Validation Error Messages

ASP.NET Web Forms   Web Forms Server Controls   Web Forms Validation


Basically, validation messages are specified using either the Text and/or the ErrorMessage property of a validation control. For example,

  • you can set the Text property to any character string or a glyph such as an asterisk ( * ) . When an error occurs, the Text will appear on the page in the location of the validation control ( for example, beside the invalid field ) .

  • you can also include a separate error message using the ErrorMessage property and add a ValidationSummary control to the page; the ErrorMessage will appear on the page in the location of the ValidationSummary control.

You can control the format — font, size, color and so on — of the validation display, using the same properties as other controls for specifying their appearance.

To format error messages

  • Set validation control properties such as the following:

Property Description
ForeColor The color of the error message text.
BackColor The color behind the text.
Font The font face, size, weight, and so on.
BorderWidth, BorderColor, and BorderStyle The size and color of a border around the error message.
CSSStyle and CSSClass Style settings that are used if the user is working with a browser that supports CSS style sheets.

NOTE: Some of the settings you make with these properties may not be supported in all browsers.

You can also modify the appearance of an error message by directly using HTML formatting elements within the specified ErrorMessage and Text properties, such as to highligh certain words using bold <b>...</b> and italic <i>...</i> markup.

If you are displaying validation errors in a summary, you can specify that a glyph appear in place of the error message in the validation control.

To display glyphs next to input controls

  1. Set the ErrorMessage property of each validation control to the error text that should appear in the ValidationSummary control.
  2. Set the Text property of each validation control to the glyph to display. The glyph can consist of any valid HTML character, such as an asterisk or even an image element.

NOTE: The glyph is displayed in place of the validation control. It’s up to you to lay out the validation control in such a way that the glyph displays properly.

See Also

Controlling Validation Message Display   Specifying Error Mesage Layout   Displaying Custom Error Messages   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