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

Comments (8) -

  • xbox red light problem

    7/29/2009 8:06:04 AM |

    I really enjoyed your article and found it to be very informative

  • How To Win The Lottery

    8/1/2009 6:20:07 AM |

    Cool - thanks for sharing that with us. BTW: I'm typing this on my new iphone - love it...

  • Annuities

    9/10/2009 11:56:44 PM |

    I like this example. Cool work.

  • pearl strands

    10/28/2009 1:19:36 AM |

    I still consider validation controls are hassle. But i like these code. thanks a lot.

  • Private Labeling

    11/14/2009 4:12:35 PM |

    With this information I got in you here in this discussion I think I might finally Know what I am going to do.

  • football shirts

    3/3/2010 10:17:52 AM |

    That's great, I never thought about The Dynamic/Static attribute displays of a validator control like that before.

  • Antonio Giampà

    4/2/2010 3:20:23 PM |

    Well i never even try anythg like this b4 in my designing it is very helpful Smile

  • John

    1/12/2011 9:57:20 AM |

    Thanks. Please post more about validator control.

Add comment

Loading