BaseValidator.Display Propriedade

Definição

Obtém ou define o comportamento de exibição da mensagem de erro em um controle de validação.Gets or sets the display behavior of the error message in a validation control.

public:
 property System::Web::UI::WebControls::ValidatorDisplay Display { System::Web::UI::WebControls::ValidatorDisplay get(); void set(System::Web::UI::WebControls::ValidatorDisplay value); };
[System.ComponentModel.Bindable(true)]
public System.Web.UI.WebControls.ValidatorDisplay Display { get; set; }
[System.Web.UI.Themeable(true)]
public System.Web.UI.WebControls.ValidatorDisplay Display { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Display : System.Web.UI.WebControls.ValidatorDisplay with get, set
[<System.Web.UI.Themeable(true)>]
member this.Display : System.Web.UI.WebControls.ValidatorDisplay with get, set
Public Property Display As ValidatorDisplay

Valor da propriedade

ValidatorDisplay

Um dos valores de ValidatorDisplay.One of the ValidatorDisplay values. O valor padrão é Static.The default value is Static.

Atributos

Exceções

O valor especificado não é um dos valores ValidatorDisplay.The specified value is not one of the ValidatorDisplay values.

Exemplos

O exemplo de código a seguir demonstra como usar a Display propriedade para especificar que o espaço para a mensagem de validação seja adicionado à página da Web dinamicamente quando a validação falhar.The following code example demonstrates how to use the Display property to specify that space for the validation message is added to the Web page dynamically when validation fails.

Importante

Este exemplo tem uma caixa de texto que aceita a entrada do usuário, que é uma possível ameaça à segurança.This example has a text box that accepts user input, which is a potential security threat. Por padrão, as páginas da Web do ASP.NET validam que a entrada do usuário não inclui elementos de script ou HTML.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Para obter mais informações, consulte Visão geral de explorações de script.For more information, see Script Exploits Overview.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  void Button_Click(Object sender, EventArgs e) 
  {
    if (Page.IsValid)
    {
      MessageLabel.Text = "Page submitted successfully.";
    }
    else
    {
      MessageLabel.Text = "There is an error on the page.";
    }
  }
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Validator Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>Validator Example</h3>
     
      Enter a number from 1 to 10.
      <asp:textbox id="NumberTextBox" 
        runat="server"/>

      <asp:rangevalidator id="NumberCompareValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"  
        type="Integer"
        display="Dynamic" 
        errormessage="Please enter a value from 1 to 10."
        maximumvalue="10"
        minimumvalue="1"  
        text="*"
        runat="server"/>

      <asp:requiredfieldvalidator id="TextBoxRequiredValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"
        display="Dynamic" 
        errormessage="Please enter a value."
        text="*"
        runat="server"/>

      <br /><br />

      <asp:button id="SubmitButton"
        text="Submit"
        onclick="Button_Click"
        runat="server"/>
 
      <br /><br />
       
      <asp:label id="MessageLabel" 
        runat="server"/>

      <br /><br />

      <asp:validationsummary
        id="ErrorSummary"
        runat="server"/>
 
    </form>
  </body>
</html>

<%@ Page Language="VB" AutoEventWireup="False" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitButton.Click
 
    If Page.IsValid Then
    
      MessageLabel.Text = "Page submitted successfully."
    
    Else
    
      MessageLabel.Text = "There is an error on the page."
    
    End If
    
  End Sub
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Validator Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>Validator Example</h3>
     
      Enter a number from 1 to 10.
      <asp:textbox id="NumberTextBox" 
        runat="server"/>

      <asp:rangevalidator id="NumberCompareValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"  
        type="Integer"
        display="Dynamic" 
        errormessage="Please enter a value from 1 to 10."
        maximumvalue="10"
        minimumvalue="1"  
        text="*"
        runat="server"/>

      <asp:requiredfieldvalidator id="TextBoxRequiredValidator" 
        controltovalidate="NumberTextBox"
        enableclientscript="False"
        display="Dynamic" 
        errormessage="Please enter a value."
        text="*"
        runat="server"/>

      <br /><br />

      <asp:button id="SubmitButton"
        text="Submit"
        runat="server"/>
 
      <br /><br />
       
      <asp:label id="MessageLabel" 
        runat="server"/>

      <br /><br />

      <asp:validationsummary
        id="ErrorSummary"
        runat="server"/>
 
    </form>
  </body>
</html>

Comentários

Use a Display propriedade para especificar o comportamento de exibição da mensagem de erro no controle de validação.Use the Display property to specify the display behavior of the error message in the validation control. A tabela a seguir lista os valores diferentes que podem ser usados.The following table lists the different values that can be used.

Comportamento de exibiçãoDisplay behavior DescriçãoDescription
None A mensagem de validação nunca é exibida embutida.The validation message is never displayed inline.
Static O espaço para a mensagem de validação é alocado no layout da página.Space for the validation message is allocated in the page layout.
Dynamic O espaço para a mensagem de validação é adicionado dinamicamente à página se a validação falhar.Space for the validation message is dynamically added to the page if validation fails.

Observação

O comportamento de exibição depende se a validação do lado do cliente é executada.The display behavior depends on whether client-side validation is performed. Se a validação do lado do cliente não estiver ativa (porque o navegador não oferece suporte a ela ou porque foi desabilitado usando a Page.ClientTarget Propriedade Page ou EnableClientScript Property) ValidatorDisplay.Static e ValidatorDisplay.Dynamic se comportar da mesma maneira: a mensagem de erro ocupará espaço somente se for exibida.If client-side validation is not active (because the browser does not support it or because it has been disabled by using the Page.ClientTarget page directive or EnableClientScript property), ValidatorDisplay.Static and ValidatorDisplay.Dynamic behave the same way: the error message takes up space only if it is displayed. A capacidade de alocar espaço dinamicamente para a mensagem quando ela não está sendo exibida ( ValidatorDisplay.Dynamic ) funciona apenas com validação do lado do cliente.The ability to dynamically allocate space for the message when it is not being displayed (ValidatorDisplay.Dynamic) only works with client-side validation.

Esta propriedade não pode ser definida por temas ou temas de folha de estilo.This property cannot be set by themes or style sheet themes. Para obter mais informações, consulte ThemeableAttribute e temas e capas do ASP.net.For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

Aplica-se a

Confira também