shrimp rice
shrimp rice

Reputation: 322

How to get all checkbox values by one specified name at asp.net server-side?

How can I get the values from checkboxes that are added by JavaScript, regardless whether the checkboxes are checked or not?

These checkboxes are created by JavaScript client side, their values will represent some data which will be saved to the database. That's why I need to get at them server side.

Upvotes: 0

Views: 1210

Answers (1)

Icarus
Icarus

Reputation: 63966

You need to make sure that these checkboxes, when created on the client side with Javascript, have a name attribute assigned so that they are submitted in the Request.

For example:

<input type="checkbox" id="mycheck" name="mycheck" />

When the form is submitted, you can access the checkbox by looking at the request params as so:

//will probably say "on" or "checked", not sure.
string mycheckbox= HttpContext.Current.Request.Params["mycheck"];

Note that you will only see in the request parameters, the checkboxes that are checked off. If you create 5 checkboxes and only one is checked off, only the one checked off will be present in the Params collection

Upvotes: 4

Related Questions