The Summary Validator
You have great control over how validation errors are reported. For example, rather than putting error messages alongside the control, you can summarize all the validation failures with a ValidationSummary control. This control can place a summary of the errors in a bulleted list, a simple list, or a paragraph that appears on the web page or in a popup message box.
Let’s rewrite Example 8-1 to add a
ValidationSummary control at the bottom of the page. This simply
requires that you add the code shown in boldface after the
</table>
tag in Example 8-1:
</table><asp:ValidationSummary ID="ValSum" DisplayMode="BulletList"
runat="server" HeaderText="The following errors were found: "
ShowMessageBox="True" ShowSummary="True"></asp:ValidationSummary>
Here you’ve named the ValidationSummary control
ValSum
and set its
DisplayMode
property
to BulletList
. The
HeaderText
attribute holds the header that will
be displayed only if there are errors to report. You can mix the
ShowMessageBox
and
ShowSummary
attributes to display the errors in the body of the HTML document
(ShowSummary="true"
) or in a pop up message box
(ShowMessageBox="true"
) or both.
To make this work, you’ll need to add an
ErrorMessage
attribute
to the other validation controls. For example, you might modify the
first validation control as follows:
<td align=middle rowspan=1> <asp: RequiredFieldValidator id="reqFieldBooks" ControlToValidate="ddlBooks" Display="static" InitialValue="-- Please Pick A Book ...
Get Programming ASP .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.