Adding Controls to an UpdatePanel dynamically

Last post 07-24-2007 11:41 PM by chetan.sarode. 3 replies.

Sort Posts:

  • Adding Controls to an UpdatePanel dynamically

    07-24-2007, 12:31 PM

    I am attemtping to add a tabbed control to an UpdatePanel that is created during a web part's CreateChildControls function.  The intention is to have a timer scroll throught the tabs displaying content until a user selects one of the tabs.  The tab control work great when it is added to the web part controls.  When I attempt to add the tabbed control to an update panel the web part fails to load.  I can add the tabbed panel to the web part controls and I can add the update panel to the web part controls, but as soon as I try to add the tabbed control to the update panel everything goes bad.

    SOURCE CODE:  

    protected override void CreateChildControls()

    {

      _updatePanel = new UpdatePanel();

      _tabContainer = new TabContainer();

     

      ...  //Populate a list of strings with the tab header text

     

      foreach(String s in StringList)

      {

        TabPanel tp = new TabPanel();

        tp.HeaderText = s;

        _tabContainer.Tabs.Add(tp);

     

        ...  //Populate the Tab with information

      }

     

      _updatePanel.Controls.Add(_tabContainer);

      Controls.Add(_updatePanel);

    }

     
    David McWee
    MicroLink LLC
    Microsoft Federal Partner of the Year 2007
    www.microlinkllc.com
  • Re: Adding Controls to an UpdatePanel dynamically

    07-24-2007, 12:56 PM
    • Loading...
    • mgodoy_desenv
    • Joined on 02-22-2007, 7:12 PM
    • São Paulo - Brazil
    • Posts 450

    Try do:

    _updatePanel.ContentTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(IncluirControleNoContainer));

        private void IncluirControleNoContainer(Control container)
        {
            container.Controls.Add(_controle); // Set your control in place of "_controle" field.
        }

    I do that when Ajax was Atlas and it worked. I don´t tested in Ajax.

  • Re: Adding Controls to an UpdatePanel dynamically

    07-24-2007, 12:58 PM
    Answer

    u have to add to contenttempllatecontainer like this..

     

    UpdatePanel1.ContentTemplateContainer.Controls.Add(myControl);
     
    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: Adding Controls to an UpdatePanel dynamically

    07-24-2007, 11:41 PM
    Answer

    You can use

    UpdatePanel.ContentTemplateContainer.Controls.Add(control);

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter