Solved

Validator Combo Box ASP.NET

Posted on 2009-03-31
4
466 Views
Last Modified: 2013-12-17
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
Comment
Question by:kinton
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 24027367
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
 
LVL 2

Author Comment

by:kinton
ID: 24027420
Do you need to pass anything into the Java script function?
0
 
LVL 11

Accepted Solution

by:
Anurag Agarwal earned 500 total points
ID: 24027578
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
 
LVL 2

Author Closing Comment

by:kinton
ID: 31564749
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

828 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