• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 495
  • Last Modified:

Validator Combo Box ASP.NET

Hi,

I have a combo box on my ASP.NET page.  The first entry is "Please Select" with a value of 0.

I want to put a client side validator on the page that will force the user to select a value other than please select.  I have other validators against text boxes so need the warning to appear as if it was a standard ASP.NEt validator.

thanks
0
kinton
Asked:
kinton
  • 2
  • 2
1 Solution
 
Anurag AgarwalPython DeveloperCommented:
if(document.getElementById('<%=combobox.ClientID%>' ).selectedIndex == 0)
{
alert("Please select any option");
document.getElementById("<%=ddlDrop.ClientID%>").f ocus();
return false;
}
put this code in a javascript function & call that javascript function on the click click of button or the lost focus event of combobox
 
Anurag
 


0
 
kintonAuthor Commented:
Do you need to pass anything into the Java script function?
0
 
Anurag AgarwalPython DeveloperCommented:
nothing in the above code.
make sure when you call this javascript function on click event write somethig like this
onclick="return Validate()"
if Validate is the name of the javascript function
 
Anurag
0
 
kintonAuthor Commented:
Great, thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now