I am trying to add two sets of checkboxes in my asp.net project. There I am doing this:
on page load:
public static CheckBox[] chck = new CheckBox[100];
public static CheckBox[] chckbx = new CheckBox[100];
and i have a functions:
public void generatecheckbox1()
{
for (int i = 0; i < 99; i++)
{
chck[i] = new CheckBox();
chck[i].ID = chck + Convert.ToString(i);
chck[i].Text = chck + Convert.ToString(i);
pnlcom1.Controls.Add(chck[i]);
pnlcom1.Controls.Add(new LiteralControl("<br />"));
chckbx[i] = new CheckBox();
chckbx[i].ID = chckbx + Convert.ToString(i);
chckbx[i].Text = chckbx + Convert.ToString(i);
pnlcom2.Controls.Add(chckbx[i]);
pnlcom2.Controls.Add(new LiteralControl("<br />"));
}
}
and i am calling this function here:
protected void ddluserwebser_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddluserwebser.SelectedItem.Text == "Custom")
{
generatecheckbox1();
}
}
The problem is i am getting an error page like this:

its saying this:
Multiple controls with the same ID 'System.Web.UI.WebControls.CheckBox[]0' were found. FindControl requires that controls have unique IDs.
But I am assigning different ids.. what should i do?
generatecheckbox1only once or multiple times maybe on postback?chck[i].ID = chck + Convert.ToString(i);needs to bechck[i].ID = "chck" + Convert.ToString(i);