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 as shown in the code snippet
from 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="-- ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access