Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Listbox validation problem in Javascript and asp.net

Posted on 2010-11-26
2
Medium Priority
?
637 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

664 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