[CLOSED] Dynamically changing control hierarchy

  1. #1

    [CLOSED] Dynamically changing control hierarchy

    Below is a code snippit that demonstrates a problem I'm seeing.

    What I'm trying to do is dynamically change the control heirarchy after it is already built. In this case, I have a ColumnLayout with two Columns, each with a Panel. Then I want to replace one of the Panels with a FieldSet.

    Here is what I'm seeing:
    1) Test = 1. This works, if I make the change before the Column is added to the Layout. Either ID works.

    2) Test = 2. If I use a new ID, the Panel is still rendered and not FieldSet even though I cleared that Column. It doesn't seem to know about the FieldSet. If I try to add the fieldset with the same ID as the Panel, I get an 'ID Already Initialized' exception in ScriptManger.RegiserInitID.

    Obviously, when the Column is added to the Layout, the ScriptManger is doing some kind of initializaion of each ID, and keeping a list of these IDs.

    I see two issues here:
    1) When a control is removed, it is not de-initialized and removed from the list. Shouldn't it be?
    2) Shouldn't the 'Init' of all children controls happen when the controls are added to the page's control heirarchy, rather when its just added to a parent. In this case 'layout' is not yet part of a page's control heirarchy. I thought this delayed event-catch-up was standard asp.net control lifecycle behavior? No?

    In any case, I need a solution of some sort.

    Thanks







    private Cool.Layout BuildLayout()
    {
      Cool.ColumnLayout layout = new Cool.ColumnLayout();
      Cool.LayoutColumn col1   = new Cool.LayoutColumn{ColumnWidth=(decimal)0.5};
      Cool.LayoutColumn col2   = new Cool.LayoutColumn{ColumnWidth=(decimal)0.5};
      Cool.Panel        panel1 = new Cool.Panel{BodyStyle="padding:5px;", ID="left",  Title="Left Panel"};
      Cool.Panel        panel2 = new Cool.Panel{BodyStyle="padding:5px;", ID="right", Title="Right Panel"};
       
      col1.Items.Add(panel1);
      col2.Items.Add(panel2);
          
      int     test      = 2;      
      bool    useNewId  = false;       
      string  newId     = useNewId ? "aNewId" : "right" ;
         
      if(1 == test)
      {
        col2.Items.Clear();
        col2.Items.Add(new FieldSet{ID=newId, Title="Right FieldSet"});
      }
          
      layout.Columns.Add(col1);
      layout.Columns.Add(col2);
          
      if(2 == test)
      {
        col2.Items.Clear();
        col2.Items.Add(new FieldSet{ID=newId, Title="Right FieldSet"});
      }
      return layout;
    }
  2. #2

    RE: [CLOSED] Dynamically changing control hierarchy

    Hi,

    Add the following code into the second 'if statement after 'Clear' calling

                layout.Items.Remove(panel2);
                layout.LazyItems.Remove(panel2);
                layout.Controls.Remove(panel2);
  3. #3

    RE: [CLOSED] Dynamically changing control hierarchy

    OK, this works.

    But why do I have to do this? Shouldn't the framework handle this? Isn't this a bug?
  4. #4

    RE: [CLOSED] Dynamically changing control hierarchy

    Hi,

    I agree to the fact that it is a bug. We will think how to correct handle such cases
  5. #5

    RE: [CLOSED] Dynamically changing control hierarchy

    OK, thanks.

    I would think you would just hook the events that remove the panel from the LayoutColumn and do the needed cleanup. I suspect that you will have similar issues in other layouts as well.

    Please keep me informed if you make any changes in this area.
  6. #6

    RE: [CLOSED] Dynamically changing control hierarchy

    Bumping topic. We (dev team) need a status update and/or decision on what to do with this issue.

    Geoffrey McGill
    Founder
  7. #7

    RE: [CLOSED] Dynamically changing control hierarchy

    Hi,

    Fixed. Now all items removing (clearing collection or removing of the particular item) should handled correctly (removing from Items, Controls and LazyItems)


    Please update from SVN and retest.
    Please note that 1.0 version is fixed only at this moment

Similar Threads

  1. [CLOSED] Tabstrip tab items and dynamically changing titles
    By UGRev in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Oct 13, 2011, 9:31 AM
  2. [CLOSED] Dynamically Changing GridPanel Paging in DirectEvent
    By mbb in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 18, 2011, 10:40 AM
  3. [CLOSED] Changing inputtextmask Mask dynamically
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 01, 2010, 2:57 AM
  4. Changing event mask Msg dynamically
    By okutbay in forum 1.x Help
    Replies: 0
    Last Post: Mar 09, 2010, 8:23 AM
  5. Dynamically changing PagingToolBar's PageSize
    By r_honey in forum 1.x Help
    Replies: 8
    Last Post: Jan 22, 2009, 7:26 AM

Posting Permissions