Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Listbox validation problem in Javascript and asp.net

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

916 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