ASP.NET – Pass the parameters to the server when clicking

I have an ASP.NET webpage with a table of checkboxes and a button. I need to find the IDs of all the checkboxes that are checked when the button click occurs. Collect IDs After the list is listed, 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 don’t use a server control for checkboxes or dynamically add checkboxes at runtime, you can use an alternative to the previous answer, which is to iterate the collection of forms sent as part of a postback. If the checkbox is checked, its ID will be added as its key and the value is “on” to this collection. If it is not checked, it will not be added to the collection. To use this method, you need to make sure that some kind of Naming convention so that you can identify the checkbox ID you are using:

foreach (var key in Request.Form.AllKeys)
{< br /> if (key.EndsWith("checkbox", true, null))
{
// If entry found then this checkbox has been checked
}
}

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
}
}

Leave a Comment

Your email address will not be published.