Share via


Controle ValidationSummary (referênciaGeral )

Exibe uma lista de todos os erros de validação na página da Web.

<asp:ValidationSummary
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CssClass="string"
    DisplayMode="List|BulletList|SingleParagraph"
    EnableClientScript="True|False"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    HeaderText="string"
    Height="size"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    ShowMessageBox="True|False"
    ShowSummary="True|False"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    ToolTip="string"
    ValidationGroup="string"
    Visible="True|False"
    Width="size"
/>

Comentários

O ValidationSummary controle permite que você resumir as mensagens de erro de todos os controles de validação em uma página da Web em um único local. O resumo pode ser exibido como uma lista, uma lista com marcadores ou um único parágrafo, com base no valor de DisplayMode propriedade. A mensagem de erro exibida na ValidationSummary controlar para cada controle de validação na página é especificado pelo ErrorMessage a propriedade de cada controle de validação. Se a ErrorMessage a propriedade do controle de validação não está definida, nenhuma mensagem de erro é exibida na ValidationSummary o controle para esse controle de validação. Você também pode especificar um título personalizado na seção de cabeçalho do ValidationSummary controle definindo a HeaderText propriedade.

Você pode controlar se a ValidationSummary controle é exibido ou ocultado definindo a ShowSummary propriedade. O resumo também pode ser exibido em uma caixa de mensagem definindo a ShowMessageBox propriedade para true.

Para obter mais informações sobre o ValidationSummary controle, consulte o System.Web.UI.WebControls.ValidationSummary classe.

Exemplo

O exemplo de código a seguir demonstra como usar o ValidationSummary o controle para resumir os controles de entrada que falharam na validação na página.

Observação de segurançaObservação sobre segurança

Este exemplo tem uma caixa de texto que aceita entrada do usuário, que é uma ameaça potencial de segurança.Por padrão, páginas Web ASP.NET validam se as entradas de usuário não incluem scripts ou elementos HTML.Para obter mais informações, consulte Visão geral de scripts maliciosos.

 <h3>ValidationSummary Sample</h3>
<br />

<form id="Form1" runat="server">

   <table cellpadding="10">
      <tr>
         <td>
           <table style="background-color:#eeeeee; padding: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="center" 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>
 <h3>ValidationSummary Sample</h3>
<br />

<form id="Form1" runat="server">

   <table cellpadding="10">
      <tr>
         <td>
    <table style="background-color:#eeeeee; padding: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="center" 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>

Consulte também

Referência

ValidationSummary

Outros recursos

Sintaxe de controle do servidor de validação