Decrease Font Size
Increase Font Size
   BLOG

The Dynamic/Static attribute displays of a validator control

A while ago, one of my friend has asked me what the different between the Dynamic/Static attribute displays of the validator control. Below is the brief demonstration of it.

<table class="style1">
        <tr>
            <td>
    <asp:Label ID="Label1" runat="server" Text="Enter Number between 1 and 100: "></asp:Label>
    <asp:TextBox ID="TextBox1" runat="server" Width="50px" CausesValidation="True"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator" 
                    Display="Dynamic">Required !!!</asp:RequiredFieldValidator>
                 <asp:RangeValidator ID="RangeValidator1" runat="server" 
                    ControlToValidate="TextBox1" ErrorMessage="RangeValidator" 
                    MaximumValue="100" MinimumValue="1" Display="Dynamic">out of range</asp:RangeValidator>
            </td>
            <td>
    <asp:Label ID="Label2" runat="server" Text="Enter Number between 101 and 200: "></asp:Label>
    <asp:TextBox ID="TextBox2" runat="server" Width="50px" CausesValidation="True"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                    ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox2">Required 2!</asp:RequiredFieldValidator>
                 <asp:RangeValidator ID="RangeValidator2" runat="server" 
                    ErrorMessage="RangeValidator" ControlToValidate="TextBox2" 
                    MaximumValue="200" MinimumValue="101">out of range</asp:RangeValidator>
            </td>
        </tr>
        <tr>
            <td class="style2">
                <asp:Button ID="Button1" runat="server" Text="Button" />
            </td>
            <td>
                 </td>
        </tr>
 </table>

The output from the above code

output example 1

 output example 2

Explanation:

The space in the first column for the validation message is dynamically added to the page if fails.

The space in the second column is reserved / allocated for the validation control in the page layout