Partilhar via


Como: Controle validação erro mensagem Display for ASP.NET servidor Controls

In Microsoft Visual Web Developer, you can display error message text in four different ways, as described in the following table.

Método de exibição

Descrição

Interno

The error message appears next to the control, in the place where the validation control is located.

Resumo

The error message is displayed in a separate summary of all errors, which is available only when the user submits the page.Optionally, the error message can appear in a message box, but this option is available only in browsers that support dynamic HTML (DHTML).

Inline and summary

The error message can be different in the summary and inline.You can use this option to show a shorter error message inline, with more detail in the summary, or to show an error glyph next to the input field and an error message in the summary.

Personalizado

You can create your own error message display.Para obter mais informações, consulte Como: Exibir mensagens de validação do servidor lado personalizadas para controles de servidor ASP.NET.

If you want to display summarized error messages, you need to add a control to the page.

To display summarized error messages

  1. Add a ValidationSummary control to the page at the location where you want to display the collected error messages.

  2. Set the ErrorMessage and Display properties of the individual validation controls.

  3. Set the DisplayMode property of the summary control to format the error messages, using one of the following values that are defined in the ValidationSummaryDisplayMode enumeration:

    Valor

    Exibir

    BulletList

    (Default) Each error message appears as a bulleted item.

    List

    Each error message appears on its own line.

    SingleParagraph

    Each error message appears as a sentence in a paragraph.

  4. If you are associating individual validation controls with validation groups, then you will need to use one ValidationSummary control for each validation group.

To display error messages inline and as a summary, you need to set different combinations of properties in the individual validation controls.

To display inline and summarized error messages

  1. Add a ValidationSummary control as described in the previous procedure.

  2. Set the ErrorMessage, Text, and Display properties of the individual validation controls according to the following table:

    Opção

    Requires ValidationSummary control

    Property settings on validation control

    Inline only

    Não

    Display = Static or Dynamic

    ErrorMessage = <error text> or Text = <error text>

    Summary only (including optional message box)

    Sim

    Display = None

    ErrorMessage = <error text> or Text = <error text>

    Inline and summary (including optional message box)

    Sim

    Display = Static or Dynamic

    ErrorMessage = <error text for summary>

    Text = <inline error text or glyph>

If the client is running a browser that supports DHTML, summarized error messages can also appear in a message box.

To display summarized error messages in a message box

  1. Set the ShowMessageBox property of the ValidationSummary control to true.

    When the user submits the page, errors are displayed in both the ValidationSummary control and the message box.

  2. To display summarized error messages only in a message box, set the ShowSummary property to false.

Consulte também

Tarefas

Como: Especificar layout para mensagens in-loco em controles de servidor ASP.NET

Referência

Validando Entrada de Usuário em Páginas da Web ASP.NET