Decrease Font Size
Increase Font Size
   BLOG

The Dynamic/Static attribute displays of a validator control

by Admin 28. June 2009 18:20

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

 

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

Tags: , , ,

ASP.NET

Comments

8/1/2009 4:06:04 PM #

xbox red light problem

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

xbox red light problem Ukraine

8/4/2009 2:20:07 PM #

How To Win The Lottery

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

How To Win The Lottery United States

9/14/2009 7:56:44 AM #

Annuities

I like this example. Cool work.

Annuities United States

10/31/2009 9:19:36 AM #

pearl strands

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

pearl strands United States

11/18/2009 12:12:35 AM #

Private Labeling

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

Private Labeling United States

3/6/2010 6:17:52 PM #

football shirts

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

football shirts United Kingdom

4/5/2010 11:20:23 PM #

Antonio Giampà

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

Antonio Giampà United States

1/15/2011 5:57:20 PM #

John

Thanks. Please post more about validator control.

John Republic of the Philippines