+1-888-365-2779
Try Now
More in this section

Forums / Security / Hide menu item if logged in

Hide menu item if logged in

5 posts, 1 answered
  1. Dave Mateer
    Dave Mateer avatar
    15 posts
    Registered:
    07 Apr 2010
    29 Jul 2010
    Link to this post
    Hi

    I have a main menu item called Register.  If the user then logs in, is there a way to hide that menu item?

    I'm using SF3.7

    Regards

    Dave
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jul 2010
    Link to this post
    Hi Dave Mateer,

    You can subscribe for ItemDataBound event of your control and there get the menu item - RadMenuItem. Check whether the request is authenticated -if(Page.Request.IsAuthenticated) and if this returns true set Visible property of the RadMenuItem to false.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Dave Mateer
    Dave Mateer avatar
    15 posts
    Registered:
    07 Apr 2010
    30 Jul 2010
    Link to this post
    Hi Ivan

    Many thanks for the reply.  I'm currently using a RadTabStrip in a template to give me the main horizontal menu.

    I'm modifying Sitefinity/UserControls/Navigation35/SiteTabstrip.asx 

    I've tried:
    <telerik:RadTabStrip ID="RadTabstrip1" runat="server" EnableViewState="false" OnTabDataBound="RadTabstrip1_TabDataBound"  OnDataBound="RadTabstrip1_DataBound">
    </telerik:RadTabStrip>

    and:
    protected void RadTabstrip1_DataBound(object sender, EventArgs e)
        {
            //RadMenuItem x = e.Item;
     
            // find the menu item I want to hide (called Register)
             
            //RadMenuItem menuItem = RadTabstrip1.FindTabByText("Register");
            var tabs = RadTabstrip1.GetAllTabs();
             
     
            //if (Page.Request.IsAuthenticated) {
            //    menuItem.Visible = false;
            //}
        }
     
        protected void RadTabstrip1_TabDataBound(object sender, RadTabStripEventArgs e)
        {
            var x = 1;
        }

    However can't get either of the methods to fire (test code in there!).  Any help / examples gratefully appreciated.

    Regards

    Dave


  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    30 Jul 2010
    Link to this post
    Hello Dave Mateer,

    The TabStrip is not populated in data bound event. It is populated in Load Event. You can see bellow how to achieve what you are looking for:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.ShowOnlyFirstLevel)
        {
            UserManager userManager = new UserManager();
            MembershipUser currentUser = userManager.GetUser();
            SiteMapNode rootNode = SiteMap.RootNode;
            foreach (SiteMapNode node1 in rootNode.ChildNodes)
            {
                if (currentUser == null)
                {
                    RadTab tab = new RadTab();
                    tab.Text = node1.Title;
                    tab.NavigateUrl = node1.Url;
                    this.RadTabstrip1.Tabs.Add(tab);
                }
            }
     
            CmsSiteMapNode currentNode = SiteMap.CurrentNode as CmsSiteMapNode;
     
            if (currentNode != null && currentNode.ParentNode != null)
            {
                while (currentNode.ParentNode != rootNode)
                {
                    CmsSiteMapNode tempNode = currentNode.ParentNode as CmsSiteMapNode;
                    if (tempNode == null)
                        break;
                    currentNode = tempNode;
                }
                RadTab item = this.RadTabstrip1.FindTabByUrl(this.ResolveUrl(currentNode.Url));
                if (item != null)
                {
                    // here you can set the style for the top-level item  
                    item.Selected = true;
                }
            }
            else if (this.RadTabstrip1.Tabs.Count > 0)
            {
                this.RadTabstrip1.Tabs[0].Selected = true;
            }
        }
        //if you have set up the tab strip to show all nodes you should extend the Filltabstrip method
        else
        {
            SiteMapNode root = this.GetStartingNode();
            FillTabStrip(root, this.RadTabstrip1.Tabs, 0);
        }
    }


    Greetings,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Dave Mateer
    Dave Mateer avatar
    15 posts
    Registered:
    07 Apr 2010
    31 Jul 2010
    Link to this post
    Hi Radoslav Georgiev

    Many thanks - that works great.  I'm currently only using the first level so:

    if ((Page.Request.IsAuthenticated) && (tab.Text == "Register"))
                    {}
                    else
                        this.RadTabstrip1.Tabs.Add(tab);


    Regards

    Dave
Register for webinar
5 posts, 1 answered