The Summary Control

You can decide 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 pop-up message box.

Create a copy of RequiredFieldValidator called RequiredFieldValidatorSummary. Add a ValidationSummary control at the bottom of the page, which requires that you add the following code after the </table> tag:

<asp:ValidationSummary
   ID="ValSum" runat="server"
   DisplayMode="BulletList"
   HeaderText="The following errors were found: "
   ShowSummary="True" />

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"), 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:

<asp:RequiredFieldValidator runat=server
   id="reqFieldBooks"
   ControlToValidate="ddlBooks"
   Display="Static"
   SetFocusOnError=true
   InitialValue="-- Please Pick A Book --"
 ErrorMessage = "You did not choose a book from the ...

Get Programming ASP.NET, 3rd Edition 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.