How to achieve this in the button click handler in the code-behind file? That is, the IDs of all checkboxes that are checked when the button click occurs.
I want to execute it in the code behind because the code-behind file contains some functions that create charts and export them as PDF, And create a chart according to the selected checkbox.
Please suggest.
Cheers
foreach (var key in Request.Form.AllKeys)
{< br /> if (key.EndsWith("checkbox", true, null))
{
// If entry found then this checkbox has been checked
}
} pre>
I have an ASP.NET webpage with a table of checkboxes and a button. I need to find the IDs of all checkboxes that are checked when the button click occurs. After the ID list is collected, it needs to be passed to the server. I can use jQuery and PageMethods to complete it.
How to achieve this in the button click handler in the code-behind file? That is, the IDs of all checkboxes that are checked when the button click occurs.
I want to execute it in the code behind because the code-behind file contains some functions that create charts and export them as PDF, And create a chart according to the selected checkbox.
Please suggest.
Cheers
If you are not using Server controls for checkboxes or dynamically adding checkboxes at runtime, you can use an alternative to the previous answer, which is to iterate the collection of forms sent as part of the postback. If the checkbox is checked, its ID will be used as Its key and value is "on" to be added to this collection. If it is unchecked, it will not be added to the collection. To use this method, you need to ensure some naming convention so that you can identify the complex you are using Checkbox ID:
foreach (var key in Request.Form.AllKeys)
{
if (key.EndsWith("checkbox" , true, null))
{
// If entry found then this checkbox has been checked
}
}