Solved

Listbox validation problem in Javascript and asp.net

Posted on 2010-11-26
2
629 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
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now