Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > TabStrip > Dynamic Tab creation new controls not visible

Dynamic Tab creation new controls not visible

Feed from this thread
  • lester dsouza avatar

    Posted on Jan 16, 2007 (permalink)

    Hello All
           I am developing a solution using tab strip and multipage with page view(s) .What i am trying to achieve is this
    1. Add Page link : Adds a Tab with it's associated page view and the controls which are in it .
    2. Delete Page link : deletes the selected tab and its associated Multipage .
     The code is as below
    ASPX Page
    <div id="Div2" class="toolbar">   
                <div style="float: left; width: 90%">
                    <radTS:RadTabStrip
                    ID="RadTabStrip1"
                    runat="server"
                    Skin="Live"
                    MultiPageID="RadMultiPage1"
                    >
                    </radTS:RadTabStrip>
                </div>   
                <div  class="toolbarRight">
                            <asp:LinkButton ID="LinkButton1" runat="server"                                        OnClick="LinkButton1_Click"                                                  CssClass="toolbarActionLink">
                                 Add a  Page</asp:LinkButton>
                                <asp:LinkButton ID="LinkButton2" runat="server"                                    CssClass="toolbarActionLink"                                                       OnClick="LinkButton2_Click1">
                                    Delete Page</asp:LinkButton>
                </div>
                <radTS:RadMultiPage ID="RadMultiPage1"
                    runat="server"
                    SelectedIndex="0"
                    Height="293px"
                    Width="695px"
                    BorderStyle="Solid"
                    >
                </radTS:RadMultiPage>
            </div>
    Code Behind:
    public partial class TelerikDefault : XhtmlPage
    {
        protected System.Web.UI.WebControls.Label PageContent;
        protected System.Web.UI.WebControls.Repeater BuildingSummary;
        protected Telerik.WebControls.PageView PageView1;

        protected void Page_Load(object sender, EventArgs e)
        {  

            if (!Page.IsPostBack)
            {
                Tab tab = new Tab();
                tab.Text = string.Format("New Page {0}", 1);
                RadTabStrip1.Tabs.Add(tab);


                PageView pageView = new PageView();
                RadMultiPage1.PageViews.Add(pageView);

                BuildPageViewContents(pageView, 1);
                RadTabStrip1.SelectedIndex = 0;
              
            }

        }
       

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
          
            Tab tab = new Tab();
            tab.Text = string.Format("New Page {0}", RadTabStrip1.Tabs.Count + 1);
            RadTabStrip1.Tabs.Add(tab);

            PageView pageView = new PageView();
            RadMultiPage1.PageViews.Add(pageView);

            BuildPageViewContents(pageView, RadTabStrip1.Tabs.Count);
            RadTabStrip1.SelectedIndex = RadTabStrip1.SelectedIndex + 1;
     
        }

        private void BuildPageViewContents(PageView pageView, int index)
        {
            pageView.ID = "Page " + index.ToString();
            pageView.Controls.Add(new LiteralControl(" <B>New page</B>" + (index).ToString()));
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
            this.RadMultiPage1.PageViewItemCreated += new PageViewItemCreatedDelegate(this.RadMultiPage1_PageViewItemCreated);
            this.RadTabStrip1.TabClick += new Telerik.WebControls.TabStripEventHandler(this.RadTabStrip1_Click);
          

        }
       
        protected void LinkButton2_Click1(object sender, EventArgs e)
        {
            Tab currentTab = RadTabStrip1.InnerMostSelectedTab;

            if (currentTab != null)
            {
                ITabContainer owner = currentTab.Owner;
                owner.Tabs.Remove(currentTab);
                if (owner.Tabs.Count > 0)
                {
                    owner.SelectedIndex = 0;
                }
            }
        }

        private void RadMultiPage1_PageViewItemCreated(PageView view, int viewIndex)
        {
           BuildPageViewContents(view, viewIndex);
        }
    }
    The problem i am facing is this .
    1.when i add a tab the tab comes and the literal control is added to the tab with the value " New Page "+ Page .But on clicking the older tabs the value is not present .
    2.Each time there is a new tab the literal gets added but on on clicking a previous tab and coming back to the new one will i be able to see the new literal

      Any help in this regard is highly appreciated as the above example i have build using the documentation and examples for tab strip.

    Thanks

    Reply

  • Paul Paul admin's avatar

    Posted on Jan 16, 2007 (permalink)

    Hi Shekhar,

    Please find below you modified code that works as expected now.

    ASPX:
    <form id="form1" runat="server">  
            <div id="Div2" class="toolbar">  
                <div style="float: left; width: 90%">  
                    <radTS:RadTabStrip ID="RadTabStrip1" runat="server" MultiPageID="RadMultiPage1">  
                    </radTS:RadTabStrip> 
                </div> 
                <div class="toolbarRight">  
                    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" CssClass="toolbarActionLink">  
                                 Add a Page</asp:LinkButton> 
                    <asp:LinkButton ID="LinkButton2" runat="server" CssClass="toolbarActionLink" OnClick="LinkButton2_Click1">  
                                    Delete Page</asp:LinkButton> 
                </div> 
                <radTS:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0" Height="293px" 
                    Width="695px" BorderStyle="Solid" OnPageViewItemCreated="RadMultiPage1_PageViewItemCreated1">  
                </radTS:RadMultiPage> 
            </div> 
        </form> 

    Code-behind:
    using System;  
    using System.Data;  
    using System.Configuration;  
    using System.Collections;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using System.Web.UI.HtmlControls;  
    using Telerik.WebControls;  
     
    public partial class _Default : System.Web.UI.Page  
    {  
        protected System.Web.UI.WebControls.Label PageContent;  
        protected System.Web.UI.WebControls.Repeater BuildingSummary;  
        protected Telerik.WebControls.PageView PageView1;  
     
        protected void Page_Load(object sender, EventArgs e)  
        {  
     
            if (!Page.IsPostBack)  
            {  
                Tab tab = new Tab();  
                tab.Text = string.Format("New Page {0}", 1);  
                RadTabStrip1.Tabs.Add(tab);  
     
                PageView pageView = new PageView();  
                RadMultiPage1.PageViews.Add(pageView);  
     
                BuildPageViewContents(pageView, RadTabStrip1.Tabs.Count);  
                RadTabStrip1.SelectedIndex = 0;  
            }  
        }  
     
        protected void LinkButton1_Click(object sender, EventArgs e)  
        {  
            Tab tab = new Tab();  
            tab.Text = string.Format("New Page {0}", RadTabStrip1.Tabs.Count + 1);  
            RadTabStrip1.Tabs.Add(tab);  
     
            PageView pageView = new PageView();  
            pageView.ID = "Page " + pageView.Index.ToString();  
            RadMultiPage1.PageViews.Add(pageView);  
     
            BuildPageViewContents(pageView, RadTabStrip1.Tabs.Count);  
            RadTabStrip1.SelectedIndex = RadTabStrip1.SelectedIndex + 1;  
            RadMultiPage1.SelectedIndex = RadTabStrip1.SelectedIndex;  
        }  
     
        private void BuildPageViewContents(PageView pageView, int index)  
        {  
            pageView.ID = "Page " + index.ToString();  
            pageView.Controls.Add(new LiteralControl(" <B>New page</B>" + (index).ToString()));  
        }  
     
        protected override void OnInit(EventArgs e)  
        {  
            base.OnInit(e);  
        }  
     
        private void InitializeComponent()  
        {  
            this.Load += new System.EventHandler(this.Page_Load);  
            //this.RadMultiPage1.PageViewItemCreated += new PageViewItemCreatedDelegate(this.RadMultiPage1_PageViewItemCreated);  
            //this.RadTabStrip1.TabClick += new Telerik.WebControls.TabStripEventHandler(this.RadTabStrip1_Click);  
        }  
     
        protected void LinkButton2_Click1(object sender, EventArgs e)  
        {  
            Tab currentTab = RadTabStrip1.InnerMostSelectedTab;  
     
            if (currentTab != null)  
            {  
                ITabContainer owner = currentTab.Owner;  
                owner.Tabs.Remove(currentTab);  
                if (owner.Tabs.Count > 0)  
                {  
                    owner.SelectedIndex = 0;  
                }  
            }  
        }  
     
        protected void RadMultiPage1_PageViewItemCreated1(PageView view, int viewIndex)  
        {  
            BuildPageViewContents(view, viewIndex + 1);  
        }  



    All the best,
    Paul
    the telerik team

    Reply

  • lester dsouza avatar

    Posted on Jan 16, 2007 (permalink)

    Hello Paul
          That code helped me and now i can add pages and the last page displays the correct value ,that again leaves with another issues ,the problem of binding . it is as below
    1.I can add pages and can see the new value getting added ( literal control) in the tab.but when i select the old tab ie i add tab2 and i see New Page 2,but when i select Tab1 the value in the Tab1 page view is not present ie the value "New Page 1 " is removed

    How can that be displayed

    Thanks again

    Reply

  • Paul Paul admin's avatar

    Posted on Jan 16, 2007 (permalink)

    Hello Shekhar,

    I think you're using some older version of the control as on my side the provided code work as expected. Please upgrade to the latest version of r.a.d.tabstrip and let me know how it goes.

    Greetings,
    Paul
    the telerik team

    Reply

  • lester dsouza avatar

    Posted on Jan 16, 2007 (permalink)

    hello Paul
           \if i understand you correctly then what you are saying is that the code is fine and on selecting tabs you are able to see the corresponding page views .That seems strange as i downloaded the controls last week and i am using that .How to verify what version of the control i am using .as i know i am using .net 2.0 version ,but i dont know what is the assembly version of the controls
    thanks

    Reply

  • Paul Paul admin's avatar

    Posted on Jan 16, 2007 (permalink)

    Hello Shekhar,

    Please find attached a sample web application that demonstrates the proper work of the modified code. Let me know if you have other question and/or problems.

    Regards,
    Paul
    the telerik team
    Attached files

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > TabStrip > Dynamic Tab creation new controls not visible