Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am using javascript for one of the ascx controls in my application.
 
The ascx controls have checkbox lists inside a panel. I have a javascript function to handle the onclick of checkboxlist items.
 
I am trying to get the checkbox list as
 
var checkBoxList = document.getElementById("<%= CheckBoxList1.ClientID %>");
 
--> it gives checkbox list as null; Also trying with,
 
var checkBoxList = document.getElementById("CheckBoxList1");
 
hen also the value is null.
 
How can I get the checkboxlist item here?
Posted 20-Mar-12 23:22pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hi,
 
try to register your javascript function at runtime using scriptmanager.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

A checkbox list is a composite control. It is rendered as individual checkboxes in the client side. You will have to read each checkbox with its id or class to get the selected values.
 
View the source of the page and you will understand how a checkbox list is rendered on client side.
 
complete solution in javascript here ...
 
http://hspinfo.wordpress.com/2008/08/14/get-checkboxlist-values-using-javascript/[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Make sure you are putting this code in aspx page. ClientID will not work in external js file.
For external js file, try following in jQuery:
 
$("[id*=CheckBoxList1] input:checkbox").prop('checked', true);
 
For more information to get/set checkboxlist items in jquery, check following:
 
ASP.NET CheckBoxList Operations with jQuery[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you can use jQuery you can try selecting the checkboxlist using the jQuery Selector. It will be easier and can be altered as much.
 
$("#{runtime id of the element")
 
To get started you may refer this
 
http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery[^]
 
And for jQuery selectors, you may refer this
 
http://api.jquery.com/category/selectors/[^]
 
If you dont want to go with jQuery please provide info on what client side event you are trying to get the checkbox list. Is that within the onclick event?
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 540
1 Tadit Dash 305
2 Sergey Alexandrovich Kryukov 250
3 Peter Leow 190
4 OriginalGriff 148
0 Sergey Alexandrovich Kryukov 9,395
1 OriginalGriff 5,473
2 Peter Leow 4,150
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 15 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid