Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RequiredFieldValidator on dropdownlist

Posted on 2004-09-23
7
Medium Priority
?
1,328 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
  • 4
  • 2
6 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

824 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