Solved

RequiredFieldValidator on dropdownlist

Posted on 2004-09-23
7
1,322 Views
Last Modified: 2008-02-01
How can I force web users to explicitly select an option on the dropdowlist?  By default, dropdownlist selects the one appears.  It makes RequiredFieldValidator on dropdownlist useless.  

Do I miss something about the Validator?  If I can not make the validator to work,  I can do dynimic validation on the server side but I don't know the best practice to do client validation.

Please help.

Biang
0
Comment
Question by:Jinghui Li
[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
  • 4
  • 2
7 Comments
 
LVL 15

Expert Comment

by:praneetha
ID: 12137951
i guess since something is allready selected...it won't fire the required field validator...

you can instead write javascript to check if the dropdownlist index chnaged
0
 

Author Comment

by:Jinghui Li
ID: 12138263
I am inspired by this article in google.  Use CompareValidator with NotEqual to the default selected value.

http://www.google.com/groups?q=requiredfieldvalidator,+dropdownlist&hl=en&lr=&ie=UTF-8&selm=%23pCp6gYgBHA.1640%40tkmsftngp07&rnum=10
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12138293
yep that's a good idea..thank u for sharing
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 15

Accepted Solution

by:
praneetha earned 500 total points
ID: 12143804
here is the solution using required field validator....

InitialValue="0" - in required field validator - is the key thing..let "0" be the value of first element which is by default selected in dropdownlist...



<asp:RequiredFieldValidator id="RequiredFieldValidator1" style="Z-INDEX: 107; LEFT: 208px; POSITION: absolute; TOP: 224px"
                        runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="DropDownList1" InitialValue="0"></asp:RequiredFieldValidator>

                  <asp:DropDownList id="DropDownList1" style="Z-INDEX: 106; LEFT: 208px; POSITION: absolute; TOP: 184px"
                        runat="server" Width="96px">
                        <asp:ListItem Value="0">Select</asp:ListItem>
                        <asp:ListItem Value="1">1</asp:ListItem>
                        <asp:ListItem Value="2">2</asp:ListItem>
                  </asp:DropDownList>
0
 

Author Comment

by:Jinghui Li
ID: 12144079
I believe ASP.NET should have designed RequiredFieldValidator to handle this normal scenario.  Thank you  praneetha for finding it out.  I think th trick here is the setting of InitialValue.  Well done!
0
 
LVL 15

Expert Comment

by:praneetha
ID: 12144148
thank u and you are welcome..i learnt something new too...

have a good weekend
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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