get checkbox state and value from Request.Form collection

1k views Asked by At

I try to access the posted value from a checkbox and if it is checked or not. I currently have this..

<input type="checkbox" value="2" class="form-check-input" id="chk1">


            for (i = 1; i <= Convert.ToInt32(HiddenNumberOfControls.Value); i++)
        {
            chkName = ("chk" + i);
            var ctrl = Request.Form[chkName];

            if (ctrl == "on")
            {

            }

        }

I can see if the checkbox is checked or not using this but is it possible to get its value?

1

There are 1 answers

0
MTplus On

Got it working by setting the checkbox value like this .InputAttributes.Add("value", "myVal");