validating a dropdownlist

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i need to validate a dropdownlist (ddlState) in a c# asp.net webform. in
other words, i need to make sure that the user selects an item in the
dropdownlist. it contains the items:

Items Index
(Select a state) 0
Arizona 1
California 2
.....

my code that is not working:

<script type="text/javascript">
function Validate(){
if (document.Form1.ddlState.value == "(Select a state)")
{
alert("Please select a state.");
}
}
</script>
 
Hi,

use one of the ASP.NET's validators, in especifyc the RequiredFieldValidator

cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top