Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

RequiredFieldValidator on dropdownlist

Posted on 2004-09-23
7
Medium Priority
?
1,326 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
praneetha earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
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…
Suggested Courses

670 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