I thought this would work. But it’s not working. It’s never getting inside of if (c is HtmlInputCheckBox)
private string GetAllCheckBoxes(ControlCollection controls)
{
StringBuilder sb = new StringBuilder();
foreach (Control c in controls)
{
if (c.HasControls())
{
GetAllCheckBoxes(c.Controls);
}
else
{
if (c is HtmlInputCheckBox)
{
CheckBox cb = c as CheckBox;
if (cb.Checked)
{
sb.Append(cb.ID + "_1");
}
else
{
sb.Append(cb.ID + "_0");
}
}
}
}
return sb.ToString();
}
update: c is throwing somesort of error.
Parent = {InnerText = '((System.Web.UI.HtmlControls.HtmlContainerControl)(((System.Web.UI.HtmlControls.HtmlGenericControl)(c.Parent)))).InnerText' threw an exception of type 'System.Web.HttpException'}
HtmlInputCheckBoxandCheckBoxare different classes and do not inherit from the other. Anistest on one won’t work for the other and vice versa. Sounds like the control is probably an instance of aCheckBoxso change the conditional to:if (c is CheckBox)