Last post Dec 12, 2005 03:04 PM by JG2
Dec 07, 2005 03:08 PM|JG2|LINK
I dynamically add a number of user controls to a page when the user presses a button on the main page. Each control has a remove button on it which should remove that specific user control. However since the page_load on the
host page fires first - before the remove button's code, the removal doesn't take effect until an additonal post back occurs.
Could someone please let me know how to get around this? Can I force the host page to perform a post back from within the user control - i.e perform teh removal code and then programmatically cause the host to post back.
Any help would be appreciated.
Dec 07, 2005 07:03 PM|sbyard|LINK
Page Language="C#" %>
System.Collections.Generic.List<Panel> list =
void Page_Load(object sender,
list = new System.Collections.Generic.List<Panel>();
list = (System.Collections.Generic.List<Panel>)Session["TheList"];
foreach (Panel p
foreach (Control c
void Button1_Click(object sender,
Panel p =
TextBox t =
LinkButton b =
b.Text = "Remove";
b.Click += new
void b_Click(object sender,
LinkButton b = (LinkButton)sender;
void Page_PreRender(object sender,
Session["TheList"] = list;
runat="server" Text="Test Postback"
runat="server" Text="Add Control"
Dec 08, 2005 10:29 AM|JG2|LINK
Thanks for that, but I cannot get it to work. Is this is a ASP.NET 2.0 solution, or should it work with 1.1 also?
Basically it complains about the line: System.Collections.Generic.List<Panel> list =
Dec 08, 2005 12:36 PM|sbyard|LINK
Dec 08, 2005 04:50 PM|JG2|LINK
Thanks for that. It kinda works.
I have seperated the HTML from the C# into two files and made a couple of changes because I'm still using 1.1.
If I add a single LinkButton, I can remove it by clicking on it. If however I add two it raises an exception when I click on either of the link buttons.
I get the following error (I have given the controls that are added a random ID):
Multiple controls with the same ID '1937201507' were found. FindControl requires that controls have unique IDs.
Any ideas what's going on?
Dec 08, 2005 06:58 PM|sbyard|LINK
Check your id assigment algorithm (and also look in the browser source at the id's generted there).
This works OK in VS2005 for unique ID's
b.ID = Guid.NewGuid().ToString("D");
Dec 12, 2005 03:04 PM|JG2|LINK