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;
}
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;
}