keep selected tab after redirect

5 posts, 1 answers
  1. Asanka
    Asanka avatar
    3 posts
    Member since:
    Jun 2011

    Posted 14 Aug 2011 Link to this post

    I have the following scenario.

    I have a master page which contains the ribbon bar with multiple tabs.
    When a user goes to a tab and clicks on a button or a split button, i redirect to relevant page from code behind.

    protected void RadRibbonBar1_ButtonClick(object sender, Telerik.Web.UI.RibbonBarButtonClickEventArgs e)
        {
            NavigateToPage(e.Button.Text.Trim());
        }
     
     
    // ---------------------------------
     
    private void NavigateToPage(string navigationText)
        {
            switch (navigationText.ToLowerInvariant())
            {
                case "dashboard":
                    {
                        Response.Redirect("~/Default.aspx");
                        break;
                    }
                case "button 01":
                    {
                        Response.Redirect("~/Default2.aspx");
                        break;
                    }
                case "button 02":
                    {
                        Response.Redirect("~/Default3.aspx");
                        break;
                    }
                default:
                    break;
            }
        }

    Redirect happens fine & everything works except for one issue.

    >> I need to keep the tab selected after being redirected. (if user clicks on a button contained in 'tab 02', after the redirect i need the ribbonbar to keep the 'tab 02' selected; but as it is, it resets to first tab after redirect. (using 2011 Q1 with server side events...)

    Is it possible to achieve what I'm trying to do?
    If it is how can it be done?
  2. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 15 Aug 2011 Link to this post

    Hi Asanka,

     I would suggest that you use the Session (if possible in the case) in order to persist the selected tab index.

    Alternatively you can use a cookie to persist this state client-side. Check my last response in this forum thread: http://www.telerik.com/community/forums/aspnet-ajax/treeview/scrollintoview-with-ajaxified-control-doesn-t-work.aspx
    The forum discusses the persistence of state in cookie for RadTreeView, but the technique is applicable here, as well.

    I hope this helps.

    Regards,
    Nikolay Tsenkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Asanka
    Asanka avatar
    3 posts
    Member since:
    Jun 2011

    Posted 15 Aug 2011 Link to this post

    Hi Nikolay,

    Thanks for quick response.
    But I'm stuck at selecting selected index from ribbonbar & assigning it on pageload (I'm assuming pageload).
    Can you give me a code snippet.
  5. Answer
    Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 17 Aug 2011 Link to this post

    Hello Asanka,

     Here is an example:
     - MasterPage with 3 content pages. MasterPage markup:

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="Current_453862_RibbonBar_persist_selected_tab_in_master_page_MasterPage" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!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>
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager runat="server" ID="ScriptManager1" />
            <telerik:RadRibbonBar runat="server" ID="RadRibbonBar1" OnSelectedTabChange="RadRibbonBar1_SelectedTabChange">
                <telerik:RibbonBarTab Text="Tab1">
                    <telerik:RibbonBarGroup Text="Group1">
                        <Items>
                            <telerik:RibbonBarButton Text="Button1" />
                        </Items>
                    </telerik:RibbonBarGroup>
                </telerik:RibbonBarTab>
                <telerik:RibbonBarTab Text="Tab2">
                    <telerik:RibbonBarGroup Text="Group2">
                        <Items>
                            <telerik:RibbonBarButton Text="Button2" />
                        </Items>
                    </telerik:RibbonBarGroup>
                </telerik:RibbonBarTab>
                <telerik:RibbonBarTab Text="Tab3">
                    <telerik:RibbonBarGroup Text="Group3">
                        <Items>
                            <telerik:RibbonBarButton Text="Button3" />
                        </Items>
                    </telerik:RibbonBarGroup>
                </telerik:RibbonBarTab>
            </telerik:RadRibbonBar>
            <a href="Default.aspx">Default.aspx</a>
            <a href="Default2.aspx">Default2.aspx</a>
            <a href="Default3.aspx">Default3.aspx</a>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
        </div>
        </form>
    </body>
    </html>
     - Code-behind of the master page:
    using System;
     
    public partial class Current_453862_RibbonBar_persist_selected_tab_in_master_page_MasterPage : System.Web.UI.MasterPage
    {
     
        protected override void OnPreRender(EventArgs e)
        {
            if (Session["SelectedTabIndex"] != null)
                RadRibbonBar1.SelectedTabIndex = (int)Session["SelectedTabIndex"];
            base.OnPreRender(e);
        }
     
        protected void RadRibbonBar1_SelectedTabChange(object sender, Telerik.Web.UI.RibbonBarSelectedTabChangeEventArgs e)
        {
            Session["SelectedTabIndex"] = RadRibbonBar1.Tabs.IndexOf(e.Tab);
        }
    }

    I hope this helps.

    Regards,
    Nikolay Tsenkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Asanka
    Asanka avatar
    3 posts
    Member since:
    Jun 2011

    Posted 19 Aug 2011 Link to this post

    Wow that worked like a charm.

    Thanks Nikolay.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017