Incrementally create user controls

A

Andla Rand

Hi,
I would appreciate if you could help me with my source code.
I want to create web user controls dynamically each time i press the
button.
But i only get one control each time. If i use a 'for'-loop then it is
no problem.

public Control c1;
private void Button1_Click(object sender, System.EventArgs e)
{

c1 = LoadControl("WebUserControl1.ascx");
((WebUserControl1)c1).Color="green";
FindControl("WebForm1").Controls.Add(c1);
FindControl("WebForm1").Controls.Add(new HtmlGenericControl("hr"));


}

Yours sincerely
Andla
 
J

Justin Rogers

Each time you post back to the page, dynamic controls are not recreated. You
are going to have to keep track of all of your dynamically created controls and
re-instantiate them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top