Please Help! Dynamic User Controls

N

NKaufman

In my pageload I am adding multiple instances of same User control.
They all have properties ID and ParentID.

Now I also have a button in each User control and am bubbling the
event back to main form. No problem so far.

Now in the event handler method, I get the ID of the user control that
raised the event (through the ID property of sender). I now need to go
through all the user controls on my page to see which one has parentID
matching the ID of the event raising user control.

foreach (Control1 MyCo in this.Page.Controls)
{

Response.Write(MyCo.GetType());
if (MyCo.MyParentID == ParID)
MyCo.Visible = false;

}

I do not see any user control in the output of response.write

Right now, the controls are loaded everytime the page is loaded.

Please help..
 
N

NKaufman

Here is my PageLoad snippet:


HtmlTable itemTable2 = new HtmlTable();
itemTable2.Width = "1200";
HtmlTableRow itemRow2 = new HtmlTableRow();
int j = 0;

foreach (DataRow myrow in ds.Tables["Sub"].Rows)
{
HtmlTableCell itemCell1 = new HtmlTableCell();
itemCell1.Width = "200";
Control MyControl = LoadControl("Control1.ascx");
Control1 MyC = (Control1)MyControl;
MyC.MyID = Convert.ToInt32(myrow["ID"]);
MyC.MyParentID = Convert.ToInt32(myrow["ParentID"]);
MyC.ID = "Control3" + j;
MyC.MyDataRow = myrow;

MyC.BubbleClick += new
EventHandler(Default3_BubbleClick);

itemCell1.Controls.Add(MyC);
itemRow2.Cells.Add(itemCell1);

HtmlTableCell itemCell2 = new HtmlTableCell();
itemCell2.Width = "20";
itemCell2.InnerHtml=" ";
itemRow2.Cells.Add(itemCell2);
j++;
}
itemTable2.Controls.Add(itemRow2);
Panel3.Controls.Add(itemTable2);
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top