Solved

Listbox validation problem in Javascript and asp.net

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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