By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,567 Members | 1,713 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,567 IT Pros & Developers. It's quick & easy.

Incrementally create user controls

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Andla Rand" <an******@yahoo.se> wrote in message
news:O0**************@TK2MSFTNGP12.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.