I have a ASP.NET web page which contains a table of check boxes and a button. I need to find the IDs of all the check boxes which are checked when the button click happens. Once the list of IDs are collected, it needs to be passed on to the server. I am able to do it using jQuery and PageMethods.
How can I achieve this in the button click handler in the code behind file? i.e. the IDs of all the check boxes which are checked when button click happens.
I want to do it in code behind because the code behind file contains a few functions which create a chart and export it to PDF and the chart gets created based on the checked check boxes.
Please suggest.
cheers
An alternative to the previous answers that can be used if you are not using server controls for your checkboxes or the checkboxes have been added dynamically at runtime is to iterate through the Form collection sent as part of the post back. If a check box has been checked it will be added to this collection with its id as its key and a value of “on”. If it is not checked it will not be added to the collection. To use this method you will need to ensure some kind on naming convention to allow you to identify the checkbox ids you are after: