Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

using two asp.net validation controls

Posted on 2011-02-28
5
Medium Priority
?
933 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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 …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 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