How to: Control Validation Error Message Display for ASP.NET Server Controls
In Microsoft Visual Web Developer, you can display error message text in four different ways, as described in the following table.
| Display method | Description |
|---|---|
|
Inline |
The error message appears next to the control, in the place where the validation control is located. |
|
Summary |
The error message is displayed in a separate summary of all errors, which is available only when the user submits the page. Optionally, the error message can appear in a message box, but this option is available only in browsers that support dynamic HTML (DHTML). |
|
Inline and summary |
The error message can be different in the summary and inline. You can use this option to show a shorter error message inline, with more detail in the summary, or to show an error glyph next to the input field and an error message in the summary. |
|
Custom |
You can create your own error message display. For more information, see How to: Display Server Side Custom Validation Messages for ASP.NET Server Controls. |
If you want to display summarized error messages, you need to add a control to the page.
To display summarized error messages
-
Add a ValidationSummary control to the page at the location where you want to display the collected error messages.
-
Set the ErrorMessage and Display properties of the individual validation controls.
-
Set the DisplayMode property of the summary control to format the error messages, using one of the following values that are defined in the ValidationSummaryDisplayMode enumeration:
Value Display BulletList
(Default) Each error message appears as a bulleted item.
List
Each error message appears on its own line.
SingleParagraph
Each error message appears as a sentence in a paragraph.
-
If you are associating individual validation controls with validation groups, then you will need to use one ValidationSummary control for each validation group.
To display error messages inline and as a summary, you need to set different combinations of properties in the individual validation controls.
To display inline and summarized error messages
-
Add a ValidationSummary control as described in the previous procedure.
-
Set the ErrorMessage, Text, and Display properties of the individual validation controls according to the following table:
Option Requires ValidationSummary control Property settings on validation control Inline only
No
Display = Static or Dynamic
ErrorMessage = <error text> or Text = <error text>
Summary only (including optional message box)
Yes
Display = None
ErrorMessage = <error text> or Text = <error text>
Inline and summary (including optional message box)
Yes
Display = Static or Dynamic
ErrorMessage = <error text for summary>
Text = <inline error text or glyph>
If the client is running a browser that supports DHTML, summarized error messages can also appear in a message box.
To display summarized error messages in a message box
-
Set the ShowMessageBox property of the ValidationSummary control to true.
When the user submits the page, errors are displayed in both the ValidationSummary control and the message box.
-
To display summarized error messages only in a message box, set the ShowSummary property to false.