Solved

using two asp.net validation controls

Posted on 2011-02-28
5
913 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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