Solved

RequiredFieldValidator on dropdownlist

Posted on 2004-09-23
7
1,315 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
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

20 Experts available now in Live!

Get 1:1 Help Now