Solved

Listbox validation problem in Javascript and asp.net

Posted on 2010-11-26
2
636 Views
Last Modified: 2012-05-10
I got this custom validator which I want to check whether this left listbox is empty and ask user to add items from the 2nd right listbox next to it. However, I got an javascript error when I put this custom validator in my aspx.  If I take away the validator from html, adding items works.

if the validator exists in the html aspx,  adding items does not work. Please help.

   <asp:CustomValidator ID="cvChosenList" runat="server" Display="Dynamic" ErrorMessage="Managed By is required" ClientValidationFunction="assignedAreaCheck"  Width="156px">Managed By is required.</asp:CustomValidator>

and javascript


<script language="JavaScript" type="text/javascript">

function assignedAreaCheck(sender, args)
{
   var listBox = document.getElementById('lstChosenManaged');
   
   if (listBox.length>0)
   args.IsValid = true;
   else
   args.IsValid = false;

}
            
</script>

0
Comment
Question by:spiral
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 34217911
What is the script error you are getting?

Maybe use ClientID to properly reference the Listbox:

var listBox = document.getElementById('<%=lstChosenManaged.ClientID%>');
0
 

Author Comment

by:spiral
ID: 34227528
thanks Erick37.

I got an error object not found. After changing the js function, the error disappears.

I also need to change the causevalidation property of my add button to false so the validation logic will not kick in when I add items.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

636 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