Incrementally create user controls

  • Thread starter Thread starter Andla Rand
  • Start date Start date
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
 
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.
 
Back
Top