TabPanel dynamically adding an ascx control

Last post 08-26-2009 1:33 PM by kvbhaskar_dotnet@yahoo.co.in. 8 replies.

Sort Posts:

  • TabPanel dynamically adding an ascx control

    01-31-2007, 3:19 PM
    • Participant
      756 point Participant
    • jakvike
    • Member since 08-28-2003, 12:38 PM
    • Omaha, NE
    • Posts 171
    I am attempting to add an ascx control to the tabpanel.  I see that it has tabpanel.controls.add but i dont see tabpanel.contenttemplate.controls.add. ive tried adding controls to the tabpanel.controls.add but it isnt showing the controls after async postback.
    Jake
    Filed under:
  • Re: TabPanel dynamically adding an ascx control

    02-01-2007, 7:06 AM
    • Member
      8 point Member
    • dsmaage
    • Member since 01-03-2007, 7:01 PM
    • Posts 4

    I was able to get a control dynamically added, however I'm gettin errors when trying to update items in a datagrid, the usercontrol does show though.

    Hope this helps:

    Your userControl needs a ClassName defined in its directive:

    <%

    @ Control ClassName="ResourceItems" ....

    then in the aspx page you want to use it you need to refrence it, which will add it to the asp namespace for this page:

    <%

    @ Reference Control="Controls/ResourceItems.ascx" %>

    Dim tabPanel As New AjaxControlToolkit.TabPanel

    tabPanel.HeaderText = "Tab 1"

    Dim uc1 As New ASP.ResourceItems

    tabPanel.Controls.Add(uc1)

    TabContainer1.Tabs.Add(tabPanel)

  • Re: TabPanel dynamically adding an ascx control

    02-01-2007, 1:24 PM
    • Participant
      756 point Participant
    • jakvike
    • Member since 08-28-2003, 12:38 PM
    • Omaha, NE
    • Posts 171

    that didnt work, but im trying a new way.

    but im receiving a javascript error during __doPostBack. 

    Specified argument was out of the range of valid values.
    Parameter name: value

    here is my code:

    html:

     <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" OnClientActiveTabChanged="ActiveTabChanged"  OnActiveTabChanged="TabContainer1_ActiveTabChanged">              
                        </ajaxToolkit:TabContainer>

    codeBehind:

    this is done during the createChildControls event

     var ASPTab = new AjaxControlToolkit.TabPanel();
            ASPTab.Attributes["class"] = "tab " + (page.ID == currentPage1.ID ? "activetab" : "inactivetab");
            ASPTab.ID = page.ID.ToString();
            ASPTab.HeaderText = page.Title;
            ASPTab.Height = Unit.Percentage(100);
            ASPTab.Width = Unit.Percentage(100);
            ASPTab.Visible = true;
            //ASPTab.DynamicContextKey = page.ID.ToString();
            //ASPTab.DynamicServiceMethod = "SetupPage_123";
            var UpPanel = new UpdatePanel();
            UpPanel.ID = page.ID.ToString();
           UpPanel.UpdateMode = UpdatePanelUpdateMode.Conditional;
            ASPTab.Controls.Add(UpPanel);
           
            //UpdatePanel1.Controls.Add(ASPTab);
            TabContainer1.Controls.Add(ASPTab);  

    end createChildcontrols: 

        protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
            {
                var panel = TabContainer1.ActiveTab;
            this.SetupPage(panel.ClientID);
            }

    Javascript:

     function ActiveTabChanged(sender, e)
      {         
                var CurrentTab = sender;
            
                var tbPanelID = sender.get_activeTab().get_id()
                var curTab = sender.get_activeTab();
                CurrentTab.innerHTML = sender.get_activeTab().get_headerText();
               
                if ( CurrentTab.innerHTML == "Add a new tab")
                {
                    Anthem_InvokePageMethod(
                    'addNewTabLinkButton_Click',
                    [tbPanelID]
                    );
                }
                else
                {
                alert(tbPanelID);
              __doPostBack('TabContainer1', tbPanelID);
                }
      }

    Jake
    Filed under: ,
  • Re: TabPanel dynamically adding an ascx control

    02-10-2007, 2:37 PM
    • Member
      8 point Member
    • gfadda
    • Member since 02-10-2007, 7:16 PM
    • Posts 4

    Hi,

    Were you guys able to resolve this.

    I am getting the same error with the following code:

     Try
               
                If Not IsPostBack Then
                    Dim aj As New TabPanel
                    Dim us As New Control
                    Dim upd As New UpdatePanel
                    upd.ID = "testmepanel"

                    upd.UpdateMode = UpdatePanelUpdateMode.Conditional

                    us = LoadControl("Page_Controls/dbIsSmart.ascx")
                    aj = New TabPanel
                    aj.HeaderText = "Test add"
                    aj.ID = "Damian_tab_in"
                    upd.ContentTemplateContainer.Controls.Add(us)
                    aj.Controls.Add(upd)
                    Tabs.Controls.Add(aj)

                End If
               

            Catch ex As Exception

            End Try


     

  • Re: TabPanel dynamically adding an ascx control

    02-20-2007, 2:50 PM
    • Member
      138 point Member
    • Marinus
    • Member since 03-16-2006, 11:21 AM
    • Posts 38

    Did anyone get an ansver / fix for this question?
    I see a lot of questions about this tabpanel-problem, but no solutions...

  • Re: TabPanel dynamically adding an ascx control

    02-23-2007, 3:19 PM
    • Member
      8 point Member
    • gfadda
    • Member since 02-10-2007, 7:16 PM
    • Posts 4

    found a solution:

     

    Load the control in the PageInit and not the PageLoad eventBig Smile 

  • Re: TabPanel dynamically adding an ascx control

    07-17-2007, 5:33 PM
    • Member
      312 point Member
    • officialboss
    • Member since 09-13-2006, 8:15 PM
    • California
    • Posts 168

    gfadda:

    found a solution:

    Load the control in the PageInit and not the PageLoad eventBig Smile 

    Can you share some sample code? How can you load in Page_Init when you are dynamically loading UserControls based on a Button Click event?

    Please be sure to click "Mark as Answer" on the post that helped you.
  • Re: TabPanel dynamically adding an ascx control

    10-02-2007, 6:48 AM
    • Contributor
      2,216 point Contributor
    • eralper
    • Member since 10-11-2002, 4:26 AM
    • Turkey
    • Posts 339

    Hi, I have only commented out the code statement where the exception is thrown and rebuild the AjaxControlToolkit library.

    And my applications did not effected in a nagative way.

    Creating the dynamic controls in the Page_Init worked fine with setting the active tab correctly without throwing an error. But this was not enough for my case because I need the values from other methods that trigger later in the page life cycle.

    So I chosed editing the AjaxControlToolkit library, TabContainer.cs line number 124 where the ArgumentOutOfRangeException is thrown.

    I just commented out this line of code.

     

    Eralper

    http://www.kodyaz.com

     

    http://www.kodyaz.com
    http://www.eralper.com

    Our true mentor in life is science
    Peace At Home, Peace In The World
  • Re: TabPanel dynamically adding an ascx control

    08-26-2009, 1:33 PM
Page 1 of 1 (9 items)