BaseValidator.Display Property
Gets or sets the display behavior of the error message in a validation control.
[Visual Basic] Public Property Display As ValidatorDisplay [C#] public ValidatorDisplay Display {get; set;} [C++] public: __property ValidatorDisplay get_Display(); public: __property void set_Display(ValidatorDisplay); [JScript] public function get Display() : ValidatorDisplay; public function set Display(ValidatorDisplay);
Property Value
One of the ValidatorDisplay values. The default value is Static.
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentException | The specified value is not one of the ValidatorDisplay values. |
Remarks
Use the Display property to specify the display behavior of the error message in the validation control. The following table lists the different values that can be used.
| Display Behavior | Description |
|---|---|
| None | The validation message is never displayed inline. |
| Static | Space for the validation message is allocated in the page layout. |
| Dynamic | Space for the validation message is dynamically added to the page if validation fails. |
Note The display behavior depends on whether client-side validation is performed. 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 only takes up space if it is displayed. The ability to dynamically allocate space for the message when it is not being displayed (ValidatorDisplay.Static) only works with client-side validation.
Example
[Visual Basic, C#, JScript] The following 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.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Button_Click(sender As Object, e As EventArgs) Dim rand_number As Random = new Random() Select Case DropList1.SelectedIndex Case 0 Compare1.Display = ValidatorDisplay.None Require1.Display = ValidatorDisplay.None Case 1 Compare1.Display = ValidatorDisplay.Static Require1.Display = ValidatorDisplay.Static Case 2 Compare1.Display = ValidatorDisplay.Dynamic Require1.Display = ValidatorDisplay.Dynamic Case Else: End Select Compare1.ValueToCompare = rand_number.Next(1, 10).ToString() Compare1.Validate() If (Page.IsValid) Then lblOutput.Text = "You guessed correctly!!" Else lblOutput.Text = "You guessed poorly" End If lblOutput.Text &= "<br><br>" & "The number is: " & Compare1.ValueToCompare End Sub </script> </head> <body> <form runat=server> <h3>Validator Example</h3> <h5>Pick a number between 1 and 10:</h5> <asp:CompareValidator id="Compare1" ControlToValidate="TextBox1" ValueToCompare="0" Type="Integer" ForeColor="Blue" EnableClientScript="False" ErrorMessage="Incorrect guess!!" Text="Try again!!" runat="server"/> <asp:RequiredFieldValidator id="Require1" ControlToValidate="TextBox1" Type="Integer" ForeColor="Blue" EnableClientScript="False" ErrorMessage="No number entered!!" Text="Enter a number!!" runat="server"/> <asp:TextBox id="TextBox1" runat="server"/> <br><br> Select Validation Display Mode: <br> <asp:DropDownList id="DropList1" runat="server"> <asp:ListItem>None</asp:ListItem> <asp:ListItem>Static</asp:ListItem> <asp:ListItem>Dynamic</asp:ListItem> </asp:DropDownList> <br><br> <asp:Button id="Button1" Text="Submit" OnClick="Button_Click" runat="server"/> <br><br> <asp:Label id="lblOutput" Font-Name="verdana" Font-Size="10pt" runat="server"/> <br><br> <asp:ValidationSummary id="Summary1" runat="server"/> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void Button_Click(Object sender, EventArgs e) { Random rand_number = new Random(); switch(DropList1.SelectedIndex) { case 0: Compare1.Display = ValidatorDisplay.None; Require1.Display = ValidatorDisplay.None; break; case 1: Compare1.Display = ValidatorDisplay.Static; Require1.Display = ValidatorDisplay.Static; break; case 2: Compare1.Display = ValidatorDisplay.Dynamic; Require1.Display = ValidatorDisplay.Dynamic; break; default: break; } Compare1.ValueToCompare = rand_number.Next(1, 10).ToString(); Compare1.Validate(); if (Page.IsValid) { lblOutput.Text = "You guessed correctly!!"; } else { lblOutput.Text = "You guessed poorly"; } lblOutput.Text += "<br><br>" + "The number is: " + Compare1.ValueToCompare; } </script> </head> <body> <form runat=server> <h3>Validator Example</h3> <h5>Pick a number between 1 and 10:</h5> <asp:CompareValidator id="Compare1" ControlToValidate="TextBox1" ValueToCompare="0" Type="Integer" ForeColor="Blue" EnableClientScript="False" ErrorMessage="Incorrect guess!!" Text="Try again!!" runat="server"/> <asp:RequiredFieldValidator id="Require1" ControlToValidate="TextBox1" Type="Integer" ForeColor="Blue" EnableClientScript="False" ErrorMessage="No number entered!!" Text="Enter a number!!" runat="server"/> <asp:TextBox id="TextBox1" runat="server"/> <br><br> Select Validation Display Mode: <br> <asp:DropDownList id="DropList1" runat="server"> <asp:ListItem>None</asp:ListItem> <asp:ListItem>Static</asp:ListItem> <asp:ListItem>Dynamic</asp:ListItem> </asp:DropDownList> <br><br> <asp:Button id="Button1" Text="Submit" OnClick="Button_Click" runat="server"/> <br><br> <asp:Label id="lblOutput" Font-Name="verdana" Font-Size="10pt" runat="server"/> <br><br> <asp:ValidationSummary id="Summary1" runat="server"/> </form> </body> </html> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script language="JScript" runat="server"> function Button_Click(sender, e : EventArgs) { var rand_number : Random = new Random(); Compare1.ValueToCompare = rand_number.Next(1, 10).ToString(); Compare1.Validate(); if (Page.IsValid) { lblOutput.Text = "You guessed correctly!!"; } else { lblOutput.Text = "You guessed poorly"; } lblOutput.Text += "<br><br>" + "The number is: " + Compare1.ValueToCompare; } </script> </head> <body> <form runat=server> <h3>Validator Example</h3> <h5>Pick a number between 1 and 10:</h5> <asp:RequiredFieldValidator id="Require1" ControlToValidate="TextBox1" Type="Integer" ErrorMessage="No number entered!!" Text="*" Display="Dynamic" runat="server"/> <asp:TextBox id="TextBox1" runat="server"/> <asp:CompareValidator id="Compare1" ControlToValidate="TextBox1" ValueToCompare="0" Type="Integer" ErrorMessage="Incorrect guess!!" Text="*" Display="Dynamic" runat="server"/> <br><br> <asp:Button id="Button1" Text="Submit" OnClick="Button_Click" runat="server"/> <br><br> <asp:Label id="lblOutput" Font-Name="verdana" Font-Size="10pt" runat="server"/> <br><br> <asp:ValidationSummary id="Summary1" runat="server"/> </form> </body> </html>
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
BaseValidator Class | BaseValidator Members | System.Web.UI.WebControls Namespace | ValidatorDisplay