How can I find dynamically generated Html Checkboxes from C#. Need to find them by id and mark them as checked.
This code generates the HTML first:
StringBuilder sbHtml = new StringBuilder("");
sbHtml.Append("<div class=\"checkboxBtn\">");
sbHtml.Append("<input type=\"checkbox\" runat=\"server\"
class=\"chkBx\" id=\"" +
Convert.ToString(someid) + "\" />");
sbHtml.Append("<label>Compare</label>");
sbHtml.Append("</div>");
and the rendered HTML is
<div class="checkboxBtn">
<span class="uncheked"></span>
<input type="checkbox" runat="server" class="chkBx" id="23"></input>
<label>Compare</label>
</div>
There are many such checkboxes and I would like to find them by IDs
string[] PhoneIds = {"11","23","43"};
foreach(string id in PhoneIds)
{
HtmlInputCheckBox cBox = form1.FindControl(id) as HtmlInputCheckBox;
if(cBox!=null)
{
//cb.checked = true;
}
}
The if condition always fails as if the checkboxes dont exist. What should be done here.