Please Help! Dynamic User Controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NKaufman

    #1

    Please Help! Dynamic User Controls

    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.Contr ols)
    {

    Response.Write( MyCo.GetType()) ;
    if (MyCo.MyParentI D == 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..

  • NKaufman

    #2
    Re: Please Help! Dynamic User Controls

    Here is my PageLoad snippet:

    HtmlTable itemTable2 = new HtmlTable();
    itemTable2.Widt h = "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("Co ntrol1.ascx");
    Control1 MyC = (Control1)MyCon trol;
    MyC.MyID = Convert.ToInt32 (myrow["ID"]);
    MyC.MyParentID = Convert.ToInt32 (myrow["ParentID"]);
    MyC.ID = "Control3" + j;
    MyC.MyDataRow = myrow;


    MyC.BubbleClick += new
    EventHandler(De fault3_BubbleCl ick);


    itemCell1.Contr ols.Add(MyC);
    itemRow2.Cells. Add(itemCell1);


    HtmlTableCell itemCell2 = new HtmlTableCell() ;
    itemCell2.Width = "20";
    itemCell2.Inner Html=" ";
    itemRow2.Cells. Add(itemCell2);
    j++;
    }
    itemTable2.Cont rols.Add(itemRo w2);
    Panel3.Controls .Add(itemTable2 );


    Comment

    Working...