Compartir a través de


ValidationSummary Control

Displays a list of all validation errors on the Web page.

<asp:ValidationSummary 
     id="programmaticID" 
     DisplayMode="BulletList | List | SingleParagraph" 
     EnableClientScript="true | false"
     ShowSummary="true | false"
     ShowMessageBox="true | false"                        
     HeaderText="TextToDisplayAsSummaryTitle"
     runat="server"/>

Remarks

The ValidationSummary control allows you to summarize the error messages from all validation controls on a Web page in a single location. The summary can be displayed as a list, a bulleted list, or a single paragraph, based on the value of the DisplayMode property. The error message displayed in the ValidationSummary control for each validation control on the page is specified by the ErrorMessage property of each validation control. If the ErrorMessage property of the validation control is not set, no error message is displayed in the ValidationSummary control for that validation control. You can also specify a custom title in the heading section of the ValidationSummary control by setting the HeaderText property.

You can control whether the ValidationSummary control is displayed or hidden by setting the ShowSummary property. The summary can also be displayed in a message box by setting the ShowMessageBox property to true.

For detailed information on the ValidationSummay control, see the ValidationSummary class.

Example

The following example demonstrates how to use the ValidationSummary control to summarize the input controls that fail validation on the page.

<html>
<head>

</head>
<body>

   <h3>ValidationSummary Sample</h3>
   <p>

   <form runat="server">

      <table cellpadding="10">
         <tr>
            <td>
               <table bgcolor="#eeeeee" cellpadding="10">

                  <tr>
                     <td colspan="3">
                        <b>Credit Card Information</b>
                     </td>
                  </tr>
                  <tr>
                     <td align="right">
                        Card Type:
                     </td>
                     <td>
                        <asp:RadioButtonList id="RadioButtonList1" 
                             RepeatLayout="Flow"
                             runat=server>

                           <asp:ListItem>MasterCard</asp:ListItem>
                           <asp:ListItem>Visa</asp:ListItem>

                        </asp:RadioButtonList>
                     </td>
                     <td align="middle" rowspan="1">
                        <asp:RequiredFieldValidator
                             id="RequiredFieldValidator1"
                             ControlToValidate="RadioButtonList1"
                             ErrorMessage="Card Type."
                             Display="Static"
                             InitialValue="" 
                             Width="100%" 
                             Text="*"
                             runat="server"/>
                     </td>
                  </tr>
                  <tr>
                     <td align="right">
                        Card Number:
                     </td>
                     <td>
                        <asp:TextBox id="TextBox1" 
                             runat="server" />
                     </td>
                     <td>
                        <asp:RequiredFieldValidator
                             id="RequiredFieldValidator2"
                             ControlToValidate="TextBox1" 
                             ErrorMessage="Card Number. "
                             Display="Static"
                             Width="100%"
                             Text="*" 
                             runat=server/>
                     </td>
                  </tr>

                  <tr>
                     <td></td>
                     <td>
                        <asp:Button id="Button1" 
                             Text="Validate" 
                             runat=server />
                     </td>
                     <td></td>
                  </tr>
               </table>

            </td>
            <td valign=top>
               <table cellpadding="20">
                  <tr>
                     <td>
                        <asp:ValidationSummary id="valSum" 
                             DisplayMode="BulletList"
                             EnableClientScript="true"
                             HeaderText="You must enter a value in the following fields:"
                             runat="server"/>
                     </td>
                  </tr>
               </table>

            </td>
         </tr>
      </table>

   </form>

</body>
</html>

See also

ValidationSummary Class | Validation Server Controls