How to go through Checkbox in automatically generated Webforms with Jquery

Asked

Viewed 104 times

1

How to scroll through several Checkboxes in the C# Button Click event where these Checkboxes were automatically generated with Jquery ?
The automatically generated Checkbox HTML is this:

<div class="col-md-12">
    <div id="MainContent_pnlCheckbox">
        <div id="MainContent_divCheckboxes">
            <div>
                <a>
                    <input type="checkbox" name="chkCI" id="2" runat="server" checked="checked" value="2">
                        <span>CI 2</span>
                </a>
            </div>
            <div>
                <a>
                    <input type="checkbox" name="chkCI" id="4" runat="server" checked="checked" value="4">
                        <span>CI 4</span>
                </a>
            </div>
        </div>
    </div>
</div>

The code to go through the Checkbox is:

foreach(Control item in divCheckboxes.Controls)
{
    if(item is CheckBox)
    {
        CheckBox c = item as CheckBox;
        if (c != null && c.Checked)
        {
            CIModel ci = new CIModel();
            ci.idci = int.Parse(c.ClientID);
            lCI.Add(ci);
        }
    }
}

But the above code does not find the Checkbox object:

inserir a descrição da imagem aqui

Note: I am using a Masterpage.

  • Put the aspx. :)

1 answer

0

If they were generated in Jquery or simply added in html, they only exist on the client screen and not on your server. That is, they are not server side components that were rendered by Asp.net and you won’t be able to interact with them in c# like the other controls.

But you can recover the selected values through the Request.Form

var chkCI = Request.Form.GetValues("chkCI");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.