O'Reilly logo

Programming ASP.NET, 3rd Edition by Dan Hurwitz, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required