How to go through several CheckBox in the Click event of a button with C # and these CheckBoxes were automatically generated with JQuery? Home
The HTML of the automatically generated CheckBox 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 ess:
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:
Note: I am using a MasterPage.