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)" />
The RequiredFieldValidator with the InitialValue should work. Can you provide some code that isn't working?
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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The issue was I was validating for the text instead of the value. Thanks!