gmatteson
gmatteson

Reputation: 79

Loop through all checked check boxes

I was hoping someone can point me in the right direction. I have two web pages, the first page has a number of check boxes in a form and POSTS to the second page. Is there a way to pass all the values of the checked check boxes to the second page so that I can find out which check boxes where checked?

Upvotes: 0

Views: 987

Answers (2)

4b0
4b0

Reputation: 22323

Set the checkbox values from the first page in session variables or cookies, and in second page you can catch it easily. for set the all check box value in page 1 you just loop like this:

foreach (Control ctl in form1.Controls)
 {
            if (ctl is CheckBox)
            {
                //check for checked or not and set a value in session or cookies.
            }
 } 

or use id

form1.FindControl("id");

Upvotes: 0

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

Sure, you could pass that information in the POST. I would recommend getting those check boxes into the <form> tag on the first form and then when you POST to the second form you can pull those values out using the FormCollection like this in the Load of the second form:

var element_name_value = Request.Form["element_name"].ToString();

Upvotes: 1

Related Questions