Solved

using two asp.net validation controls

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

919 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