elliottbenzle
asked on
using two asp.net validation controls
In my form I need to validate a field for both required and for range.
The problem is that if the second validation control message is pushed far to the left, because of the 1st validation control message. The code looks like this:
<asp:TextBox ID="txtClass" Width="80px" runat="server"></asp:TextB ox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Enter a valid year." ControlToValidate="txtClas s" MaximumValue="2200" MinimumValue="1800" SetFocusOnError="True" Visible="True" Display="Static"></asp:Ran geValidato r>
<asp:RequiredFieldValidato r ID="RequiredFieldValidator 4" runat="server" ErrorMessage="Enter a valid graduation date." ControlToValidate="txtClas s" Visible="False"></asp:Requ iredFieldV alidator>
And if no value is entered the error message appears far off to the left, like this
TEXT FIELD Enter a graduation date
This appears to be because the first validation control is still taking up space even when not visible.
Does anyone know a work around for this problem?
Thanks
Example page is here: http://www.glowfishtw.com/stlukes/alumni.aspx
The problem is that if the second validation control message is pushed far to the left, because of the 1st validation control message. The code looks like this:
<asp:TextBox ID="txtClass" Width="80px" runat="server"></asp:TextB
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Enter a valid year." ControlToValidate="txtClas
<asp:RequiredFieldValidato
And if no value is entered the error message appears far off to the left, like this
TEXT FIELD Enter a graduation date
This appears to be because the first validation control is still taking up space even when not visible.
Does anyone know a work around for this problem?
Thanks
Example page is here: http://www.glowfishtw.com/stlukes/alumni.aspx
Try the below settings
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Enter a valid year." ControlToValidate="txtClass" MaximumValue="2200" MinimumValue="1800" SetFocusOnError="True" Visible="True" Display="None"></asp:RangeValidator>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
using Display="Dynamic" the validation control will occupy space only in case of incorrect entry.
ASKER
Thanks. That was it.
Have a look here : http://msdn.microsoft.com/