Avatar of VGMForbin
VGMForbin
 asked on

Validate that the default item is not selected in a DropDownList

I have a DropDownList that has the first item being "(Choose One)".  I want to set up a validator to make sure that the user cannot contine with that item selected.   I set up a RequiredFieldValidator with "(Choose One)" set as the InitialValue property, and that did not work.  I also set up a CompareValidator to test that the value wasn't equal to "(Choose One)", but that also failed.  Am I doing something incorrect?
<asp:CompareValidator
                    ID="SelecterCompareValidator"
                    runat="server"
                    ErrorMessage="Please choose an item." 
                    ControlToValidate="SelecterDownList" Display="Static" Operator="NotEqual" 
                    ValueToCompare="(Choose One)" />

Open in new window

ASP.NET

Avatar of undefined
Last Comment
VGMForbin

8/22/2022 - Mon
cdaly33

The RequiredFieldValidator with the InitialValue should work.  Can you provide some code that isn't working?
Ajay Sharma

Can you paste your DropDownList filing code?
If it's in page_load then make sure that you are filling DropDownList into the Page.IsPostBack

Try to debug the value in the button click event and analyse the default value selected.

Visit:
http://dotnetcoderoom.blogspot.com/2008/09/using-requiredfieldvalidator-with.html


amar31282



also use this one instead of compare validator

 

do you have AutoPostBack = true in DDL if yes then there might be issues with that also
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
karakav

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
VGMForbin

ASKER
The issue was I was validating for the text instead of the value.  Thanks!