Solved

using two asp.net validation controls

Posted on 2011-02-28
5
904 Views
Last Modified: 2012-05-11
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:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Enter a valid year." ControlToValidate="txtClass" MaximumValue="2200" MinimumValue="1800" SetFocusOnError="True" Visible="True" Display="Static"></asp:RangeValidator>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Enter a valid graduation date." ControlToValidate="txtClass" Visible="False"></asp:RequiredFieldValidator>

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

0
Comment
Question by:elliottbenzle
5 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35003721
Use the ValidationSummaryControl to show the error message and use the text property of the validator controls to show an *

Have a look here : http://msdn.microsoft.com/en-us/library/ms972961.aspx
0
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 35004165
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>

Open in new window

0
 
LVL 9

Accepted Solution

by:
mayank_joshi earned 500 total points
ID: 35004235
Set Property  Display="Dynamic" on validation controls.e.g.

<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Enter a valid year." ControlToValidate="txtClass" MaximumValue="2200" MinimumValue="1800" SetFocusOnError="True" Visible="True" Display="Dynamic"></asp:RangeValidator>
0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35004246
using Display="Dynamic"  the validation control will occupy space only in case of incorrect entry.
0
 
LVL 4

Author Closing Comment

by:elliottbenzle
ID: 35006439
Thanks. That was it.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now