I am trying to add Checkboxes dynamically to webpage
string[] words = masg.Split('~');
int size = words.Length;
CheckBox[] cbl = new CheckBox[size];
for (int i = 0; i < words.Length; i++)
{
cbl[i] = new CheckBox();
cbl[i].Text = words[i].ToString();
this.Controls.Add(cbl[i]);
// Response.Write("\n" + words[i]);
}
I am getting error
Control ‘ctl01’ of type ‘CheckBox’ must be placed inside a form tag with runat=server.
How should I proceed ? What changes to make on aspx page ? Please help.
You should change it to add in form, because
thisis referencing your Page. and any server control which you are creating programmatic or by adding on page withrunat="server"should place inside a form tag.like
or place a placeholder or panel on the form. and than you can add in it
like
If your .aspx does not contain a form tag, then you should place a form tag there
like