Show/Hide tabs

2 posts, 0 answers
  1. Ron
    Ron avatar
    113 posts
    Member since:
    Apr 2011

    Posted 16 Dec 2011 Link to this post

    Hi,

    Can somebody help me with showing and hiding tabs in code behind? I've tried many methods and none seem to work. I really appreciate your assistance with this one.

    Thanks,
    Ron.
  2. jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 16 Dec 2011 Link to this post

    Ron:

    Here's a basic sample that employs "RadTabStrip.FindTabByText(TextBox1.Text)" with the "Tab.Visible = true" properties to show/hide the RadTabStrip tabs in the code behind of a C# sample.

    "Default.aspx" Source Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <script type="text/javascript">
            //Put your JavaScript code here.
        </script>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <div style="background: url(Img/bg.gif) no-repeat; width: 600px; height: 362px; padding-top: 24px;
            text-align: left;">
            <asp:Label ID="Label1" runat="server" Text="Enter a Tab Name"></asp:Label>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            <asp:Button Text="Hide Root Tab" OnClick="hideRootTab_Click" runat="server" ID="hideRootTab"
                Style="width: 116px;"></asp:Button>
            <asp:Button Text="Show Root Tab" OnClick="showRootTab_Click" runat="server" ID="showRootTab"
                Width="131px"></asp:Button>
            <asp:Button Text="Hide Child Tab" OnClick="hideChildTab_Click" runat="server" ID="hideChildTab"
                Style="width: 116px;"></asp:Button>
            <asp:Button Text="Show Child Tab" OnClick="showChildTab_Click" runat="server" ID="showChildTab"
                Width="131px"></asp:Button>
        <br />
            <telerik:RadTabStrip ID="RadTabStrip1" runat="server">
            </telerik:RadTabStrip>
        </div>
        </form>
    </body>
    </html>
     
    "Default.aspx.cs" code behind:
    using System;
    using Telerik.Web.UI;
     
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                for (int i = 0; i < 4; i++)
                {
                    RadTab rootTab = new RadTab();
                     
                    RadTabStrip1.Tabs.Add(rootTab);
                    rootTab.Text = "Root Tab " + RadTabStrip1.Tabs.Count;
                    rootTab.Value = i.ToString();
     
                    for (int j = 0; j < 4; j++)
                    {
                        RadTab childTab = new RadTab();
                        rootTab.Tabs.Add(childTab);
                        childTab.Text = string.Format("Child Tab {0}.{1}", i + 1, rootTab.Tabs.Count);
                    }
                }
                RadTabStrip1.SelectedIndex = 0;
            }
     
        }
     
        protected void hideRootTab_Click(object sender, EventArgs e)
        {
            RadTab rootTab = RadTabStrip1.FindTabByText(TextBox1.Text);
            rootTab.Visible = false;
             
        }
     
        protected void showRootTab_Click(object sender, EventArgs e)
        {
            RadTab rootTab = RadTabStrip1.FindTabByText(TextBox1.Text);
            rootTab.Visible = true;
        }
     
        protected void hideChildTab_Click(object sender, EventArgs e)
        {
            RadTab childTab = RadTabStrip1.FindTabByText(TextBox1.Text);
            childTab.Visible = false;
        }
     
        protected void showChildTab_Click(object sender, EventArgs e)
        {
            RadTab childTab = RadTabStrip1.FindTabByText(TextBox1.Text);
            childTab.Visible = true;
        }
     
    }

    Hope this helps.

    Cheers!
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top