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

Forums / Developing with Sitefinity / Want to keep the Top menu Button Selected on Page change

Want to keep the Top menu Button Selected on Page change

3 posts, 0 answered
  1. shahid Aziz
    shahid Aziz avatar
    8 posts
    Registered:
    20 Nov 2009
    31 Dec 2009
    Link to this post
    Hi,
    i have my Top menu in the master page file, and whenever i click on some page, i want the top manu to show under which page this is. i mean i want the top menu link to remain selected on page change.

    i believe there would be some selected Index for this, but i am unable to find it for Rad Menu,

    Please help.

    best regards
    shahid Aziz
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    05 Jan 2010
    Link to this post
    Hello shahid Aziz,

    You can use SiteMenu or RadMenu controls and add the logic show below to the code behind of your control

    protected override void OnPreRender(EventArgs e)
       {
           base.OnPreRender(e);
           RadMenu1.DataBind();
           CmsSiteMapNode currentNode = SiteMap.CurrentNode as CmsSiteMapNode;
           while (currentNode != null && currentNode.ParentNode != null)
           {
               if (currentNode.ParentNode != SiteMap.RootNode)
                   currentNode = (CmsSiteMapNode)currentNode.ParentNode;
               else
                   break;
           }
           RadMenuItem item = this.RadMenu1.FindItemByUrl(this.ResolveUrl(currentNode.Url).ToString());
           if (item != null)
           {
               item.Selected = true;
               item.SelectedCssClass = selectedItemCssClass;
           }
            
       }


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. MNP
    MNP avatar
    79 posts
    Registered:
    23 Apr 2008
    19 Jan 2010
    Link to this post
    Small change to the code above would be to add in a check to see if currentNode is null. This check stops the code from breaking when the page you are editing is a template
    if (currentNode != null
            { 
                RadMenuItem item = this.RadMenu1.FindItemByUrl(this.ResolveUrl(currentNode.Url).ToString()); 
                if (item != null
                { 
                    item.Selected = true
                    item.SelectedCssClass = selectedItemCssClass; 
                } 
            } 

Register for webinar
3 posts, 0 answered