UserControl duplication (ASP.NET)

G

Guest

Hi there,
I have a user control which should be loaded when a button is clicked. But
it should also append more of the user controls when the button is clicked
more than once. It works fine to load the user control once on Button_Click
event but if the button is clicked again nothing happens. I implemented a
counter to always give the userControl a different id. What am I doing wrong?
(I think it has to do with the actual object name which is used, but this is
just a guess)

private void Button1_Click(object sender, System.EventArgs e)
{
if (Session["counter"] == null)
{
Session["counter"] = 0;
}
int i = Convert.ToInt32(Session["counter"]);
WebUserControl1 uc =
(WebUserControl1)Page.LoadControl("WebUserControl1.ascx");
PnlCases.Controls.Add(uc);
uc.ID = "wuc" + i;
i++;
Session["counter"] = i;
}
 
O

Octavio Hernandez

Chris,

I'm not sure, but I guess you'll have to store all your controls in an array
in Session and re-load them with each page load...

Regards - Octavio
 

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