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

Forums / Bugs & Issues / Page Group Bug

Page Group Bug

26 posts, 0 answered
  1. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    12 Dec 2010
    Link to this post
    Hi There,

    I've noticed that the Page Groups have a bug. If you click on a menu item that is a page group, it displays the content of the first page in the group. This behaviour is correct except one glaring issue. The actual page the site is at is still the Page Group which isn't actually supposed to be a page. This means that the URL is wrong, if you try to display the current page title (I have a widget for this) using 
    string title = new PageManager().GetPageNode(new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key)).Title;

    this also is wrong and displays the name of the Page Group and not the name of the page that is currently displayed. Finally I use a RadPanelBar as a side menu and it indicates to the user what page they're on. Since Sitefinity actually never takes the user to that page the item doesn't get hilighted.

    For me this is not acceptable behaviour and appears to be a bug. Please tell me it is and that it's not the intended behaviour as it makes no sense at all.

    Regards,
    Phill
  2. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    14 Dec 2010
    Link to this post
    Hi There,

    I'm wondering if there's any statement from Telerik as to if this is a bug or actually the intended functionality. If it's the intended functionality, what would be the recommended work around to fix it for my desired behaviour where the url and selected menu items match the content being displayed. Would a redirect in page_load of masterpage codebehind work? What property would I be looking for to see if a page is a group? If I know that I can redirect to the SiteMapNodes next sibling. It seems like a shitty work around so if there are better solutions please let me know.

    Regards,
    Phill 
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    15 Dec 2010
    Link to this post
    Hi Phill ,

    You can identify the whether a page is Group or not by checking the PageNode.Page. The Group page does not have PageData.

    var node = pageManager.GetPageNode(id);
    var isGroupPage = node.Page == null;
    if (!isGroupPage)
    {
          
    }


    You can get the first page node by using node.Nodes[0].

    The better option is calling SiteMapBase.GetFirstPageDataNode(PageNode); We have implemented a method SiteMapBase.GetActualCurrentNode(); that will be available in the next weekly build.

    Best wishes,
    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
  4. UI Crew
    UI Crew avatar
    99 posts
    Registered:
    24 Sep 2012
    21 Dec 2010
    Link to this post
    Hi,

    This definetly seems to be a bug and is not the behaviour of the navigation controls in the previous version. Clicking a page group url should take you to the url of the first page in the group however it does not. Instead it gives the content of the first page in the group on the page group url.

    This causes Google's Webmaster tools to report that there are pages with duplicate content between the page group and the first page in the group. This is certainly not desirable. 

    The problem can be seen here on the site we have deployed:


    Thanks

    Seth 
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Dec 2010
    Link to this post
    Hi Webinsite,

    How have you generated the SiteMap? Generally you should have a xml datasource with all page nodes. If you exclude the page groups or the first page you will not get duplicate content. This will increase the weight of the url.

    We will have an internal discussion about how to change the behavior of page group and the first page. Our initial idea is to expose some option for permanent redirect from the group page to the first child and vice versa, so crawlers will not be affected. Any other ideas are appreciated.

    Greetings,
    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
  6. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    21 Dec 2010
    Link to this post
    Hi Ivan,

    I had attempted to use code similar to the following in the ItemDataBound event of my main menu. Howerver by doing this it broke my code that marks the top level (level 0) menu item as selected when any child items are selected.
    SiteMapNode cNode = e.Item.DataItem as SiteMapNode;
    PageSiteNode node = (PageSiteNode)cNode;
    if (node.IsGroupPage)
    {
        SiteMapNodeCollection nodeCollection = node.ChildNodes;
        // Set the Url of the PageGroup item to the Url of the first page in group
        if(nodeCollection[0] != null)
            e.Item.NavigateUrl = nodeCollection[0].Url;
    }

    As mentioned, my little function that looks for the root node and sets the image to selected/expanded no longer works because the node.Url used in the RadMenu1.FIndItemByUrl doesn't find the required url at the expected level.  
    private void GetRootNode(SiteMapNode node)
    {
        if (node.ParentNode.ParentNode == null)
        {
            var item = RadMenu1.FindItemByUrl(Page.ResolveUrl(node.Url));
            if(item != null)
                item.ImageUrl = item.ExpandedImageUrl;
        }
        else
        {
            GetRootNode(node.ParentNode);
        }
     
    }

    So I think I might be close to a solution that works, but not quite. Maybe I need to do the first part earlier in the page life cycle?

    p.s. I agree w/ Seth that the "duplicate" content is also not a desired side effect of the current implementation in addition to the other issues I've already mentioned. I think this is a great example of "if it's not broken, don't fix it" as the behaviour in SF 3.x worked very well.

    Regards,
    Phill
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Dec 2010
    Link to this post
    Hi Phill,

    Using GetFirstPageDataNode and GetActualCurrentNode methods should fix the issue you have, because this returns the actual item and the actual url of it. Using a while loop you can highlight the path to the root. The group page does not have PageData additional check for this will return whether the parent is group or not, so you can highlight it by getting an instance to the current menu item which is in the loop - you have direct access to it from the arguments of ItemDataBound event

    Greetings,
    Ivan Dimitrov
    the Telerik Dev 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
  8. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    22 Dec 2010
    Link to this post
    Hi Ivan,

    I'm wondering if you can help me with the issue I'm having. The problem is that in order to get the GroupPage to behave as it should, I'm changing it's url to the url of the first item. The call to GetFirstPageDataNode() makes this much easier and works great in the RC2. However, this means that my RadMenu now has two nodes with the same url so my code used in the loop to find the root:
    var item = RadMenu1.FindItemByUrl(Page.ResolveUrl(node.Url));
    doesn't work.

    Is there another way I can get the root menu item of a RadMenu if the URL isn't unique?  It would be nice if there was just a simple call GetRootNode() instead of having to do a loop that calls itself.

    Thanks again for your help.
    Phill
  9. UI Crew
    UI Crew avatar
    99 posts
    Registered:
    24 Sep 2012
    22 Dec 2010
    Link to this post
    Hi Ivan,

    I just want to clarify - this bug occurs using the built in navigation control with no modifications - so I don't quite understand what you were asking about the generated sitemap.... I dropped in the SF navigation control into the page, no custom work.

    As for how to remeady the situation - if this wasn't the behaviour in 3.x for the sitemenu control why don't you just do the same thing you did in 3.x? Seems to me to be the logical thing to do.

    Cheers,

    Seth
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Dec 2010
    Link to this post
    Hi,

    Google Webmaster tools can use XML SiteMap which helps Google to find pages on your website and you can specify the web address of a single page. There is a SiteMap generator that google offers and I thought that you use this way.

    Currently when you go to a group page we load the first page in the same window and SiteMap.CurrentNode returns the group page instead of the first page. This is why we have GetActualCurrentNode method.

    We will have an internal discussion about how to change the behavior of page group and the first page. Our initial idea is to expose some option for permanent redirect from the group page to the first child and vice versa, so crawlers will not be affected. Any other ideas are appreciated.


    All the best,
    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
  11. Josh Anderson
    Josh Anderson avatar
    48 posts
    Registered:
    15 Dec 2005
    17 Feb 2011
    Link to this post
    Has there been any movement on this? I've run up against this issue as well, not for Google indexing reasons, but because I have a sidebar navigation control that uses the value of a RadSiteMap control's SelectedNode property to change the CSS of the related item in the navigation control. This control won't pick up the selected page when someone clicks on the group page on a different site-wide navigation control.

    I could fake this out by testing for the URL explicitly, but this control is reused in several areas that have similar group setups, so that wouldn't be a very robust solution.

    Josh
  12. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    07 Mar 2011
    Link to this post
    I am curious - Phil - did you get it to work?  You mentioned that you - created a menu from scratch and in the itemdatabound of the repeater changing the Url of group menu items to the url of the first item in the group.  How much from scratch did you have to create?  Can the exisiting -say navigation tree control be modified to do this?

    Thank you
    Laura

  13. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    07 Mar 2011
    Link to this post
    Hi Laura,

    I based my menu on a User Control I had created for a SF 3.7 site. Part of the reason I created it from scratch was because my design required my top level items to be graphics so this complicated things further. In case it helps, here's what I came up with

    MainMenu.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MainMenu.ascx.cs" Inherits="SitefinityWebApp.Custom.Navigation.MainMenu" %>
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
    <telerik:RadMenu ID="RadMenu1" runat="server"
        DataSourceID="SitemapDataSource1"
        EnableEmbeddedBaseStylesheet="true"
        EnableEmbeddedSkins="false"
        EnableOverlay="true"
        EnableScreenBoundaryDetection="false"
        EnableRoundedCorners="false"
        EnableShadows="false"
        DefaultGroupSettings-Width="150"
        >
    </telerik:RadMenu>



    MainMenu.ascx.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
     
    using Telerik.Sitefinity.Web;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Modules.Pages.Web.UI;
    using Telerik.Web.UI;
    using Telerik.Web.UI.Design;
     
    namespace SitefinityWebApp.Custom.Navigation
    {
        [RequireScriptManager]
        public partial class JDNAMenu : System.Web.UI.UserControl
        {
            string currentLang = "en";
     
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!this.IsDesignMode())
                {
                    this.RadMenu1.ItemDataBound += new Telerik.Web.UI.RadMenuEventHandler(RadMenu1_ItemDataBound);
                }
            }
     
            void RadMenu1_ItemDataBound(object sender, Telerik.Web.UI.RadMenuEventArgs e)
            {
                SiteMapNode cNode = e.Item.DataItem as SiteMapNode;
                PageSiteNode node = (PageSiteNode)cNode;
                // Hide the menu item if set to not show in navigation or if hidden
                if (!node.ShowInNavigation || node.Hidden)
                {
                    e.Item.Visible = false;
                }
     
                // Set group node url to url of first page to fix SF4 Page Group BUG!!!!
                if (node.IsGroupPage)
                {
                    SiteMapNode gNode = SiteMapBase.GetFirstPageDataNode(node);
                    e.Item.NavigateUrl = gNode.Url;
                }
     
                // Custom Code to support image buttons for the top level menu items
                if (e.Item.Level == 0)
                {
                    SiteMapNode dataItem = e.Item.DataItem as SiteMapNode;
                    if (dataItem != null)
                    {
                        e.Item.ImageUrl = "~/images/nav/main-" + dataItem.Title.Trim().Replace(" ", "") + "-" + currentLang + "-off.jpg";
                        e.Item.HoveredImageUrl = "~/images/nav/main-" + dataItem.Title.Trim().Replace(" ", "") + "-" + currentLang + "-on.jpg";
                        e.Item.Text = "";
     
                    }
                }
                
                // Set Current Top Level Node to Selected
                SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
                if (currentNode != null)
                {
                    var item = RadMenu1.FindItemByUrl(Page.ResolveUrl(currentNode.Url));
                    if (item != null)
                    {
                        SiteMapNode curItem = item.DataItem as SiteMapNode;
                        if (curItem != null)
                        {
                            if (item.Level == 0)
                            {
                                // Select top level item
                                item.ImageUrl = "~/images/nav/main-" + curItem.Title.Trim().Replace(" ", "") + "-" + currentLang + "-on.jpg";
                            }
                            else if (item.Level > 0)
                            {
                                // Select top menu item when a sub item is selected
                                GetRootNode(currentNode);
                            }
                        }
                    }
                }
            }
     
            /// <summary>
            /// Calls itself until it gets the section one level below the root
            /// </summary>
            /// <param name="node"></param>
            private void GetRootNode(SiteMapNode node)
            {
                if (node.ParentNode.ParentNode == null)
                {
                    var item = RadMenu1.FindItemByValue(node.Title);
                    if(item != null)
                        item.ImageUrl = item.HoveredImageUrl;
                }
                else
                {
                    GetRootNode(node.ParentNode);
                }
     
            }
        }
    }

    You can see the menu in action here www.jdna.ca

    I hope that helps. The key item was to check if the menu item was a Group and if it was, get the URL of the first node and assign it that url. I could be mistaken but I think this also helps SEO in that i now have 1 URL pointing to the content instead of 2 different URLs pointing to the same content. If you don't want an image based menu at the top level you could comment out the ImageUrl assignment and the line that sets Text = "", that should set it back to a regular text based menu. 

    Cheers,
    Phill
  14. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    07 Mar 2011
    Link to this post
    Thank you so much Phill.  For the sub nav's on the left hand side, were you able to program the starting node offset there too? Or did you have to have a different template for each main section?
  15. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    07 Mar 2011
    Link to this post
    Hi Laura, the side menu is a RadPanelBar. In the current site structure the content doesn't get grouped after the first level so I didn't have to worry about the Page Group bug there but the same approach would most likely apply. In case you haven't used it before, the site menu was as follows:

    SideMenu.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SideMenu.ascx.cs" Inherits="SitefinityWebApp.Custom.Navigation.SideMenu" %>
    <h4><asp:Literal ID="litSectionTitle" runat="server" /></h4>
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" StartingNodeOffset="1"/>
    <telerik:RadPanelBar ID="RadPanelbar1" runat="server"
        DataSourceID="SiteMapDataSource1"
        OnItemDataBound="RadPanelbar1_ItemDataBound"
        EnableViewState="false"
        AllowCollapseAllItems="false"
        ExpandMode="MultipleExpandedItems"
        Width="130"
        EnableEmbeddedSkins="false"
        EnableEmbeddedBaseStylesheet="true"
        >
    </telerik:RadPanelBar>


    SideMenu.ascx.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
     
    using Telerik.Sitefinity.Web;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Modules.Pages.Web.UI;
    using Telerik.Web.UI;
     
    namespace SitefinityWebApp.Custom.Navigation
    {
        [RequireScriptManager]
        public partial class SideMenu : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    if (!this.IsDesignMode())
                    {
                        SiteMapNode cNode = SiteMapBase.GetCurrentProvider().CurrentNode;
     
                        if (cNode != null)
                        {
                            if (cNode.ParentNode.ParentNode == null)
                            {
                                litSectionTitle.Text = new PageManager().GetPageNode(new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key)).Title;
                            }
                            else
                            {
                                GetSection(cNode);
                            }
                        }
                    }
                }
            }
     
            /// <summary>
            /// Calls itself until it gets the section one level below the root
            /// </summary>
            /// <param name="node"></param>
            protected void GetSection(SiteMapNode node)
            {
                if (node.ParentNode.ParentNode == null)
                {
                    litSectionTitle.Text = node.Title;
                }
                else
                {
                    GetSection(node.ParentNode);
                }
            }
     
            #region Properties
            [Browsable(true)]
            [Category("Navigation")]
            public int StartingNodeOffset
            {
                get
                {
                    return this.SiteMapDataSource1.StartingNodeOffset;
                }
                set
                {
                    this.SiteMapDataSource1.StartingNodeOffset = value;
                }
            }
     
     
            [Browsable(true)]
            [Category("Navigation")]
            public bool StartFromCurrentNode
            {
                get
                {
                    return this.SiteMapDataSource1.StartFromCurrentNode;
                }
                set
                {
                    this.SiteMapDataSource1.StartFromCurrentNode = value;
                }
            }
     
     
            [Browsable(true)]
            [Category("Navigation")]
            [DefaultValue(false)]
            public bool ShowStartingNode
            {
                get
                {
                    return this.SiteMapDataSource1.ShowStartingNode;
                }
                set
                {
                    this.SiteMapDataSource1.ShowStartingNode = value;
                }
            }
            #endregion
     
            #region Methods
     
            public void RadPanelbar1_ItemDataBound(object sender, RadPanelBarEventArgs e)
            {
                SiteMapNode cNode = e.Item.DataItem as SiteMapNode;
                PageSiteNode node = (PageSiteNode)cNode;
                // Hide the menu item if set to not show in navigation or if hidden
                if (!node.ShowInNavigation || node.Hidden)
                {
                    e.Item.Visible = false;
                }
            }
            #endregion
        }
    }


    p.s. one little note, in the code I posted previously you'll need to change:
    public partial class JDNAMenu 
    to 
    public partial class MainMenu 

    Again, hope that helps.
    Cheers,
    Phill
  16. Stacey
    Stacey avatar
    291 posts
    Registered:
    18 Oct 2012
    18 Apr 2011
    Link to this post
    Thank you for sharing that Phill.  I was pulling my hair out trying to figure out if I misunderstood how page groups should work.  I had the same need for menu functionality and your example put me on the right path.
  17. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    24 Apr 2011
    Link to this post
    Firstly thanks Phill, now that i know to get my naviagtion to work as expected i need to create a custom control and use that.

    secondly can we have page groups back to the way they used to be and not try and be clever with it.  if it is a group just load the first page in that group with the correct url!

    Rob
  18. Dennis
    Dennis avatar
    19 posts
    Registered:
    26 May 2009
    27 Apr 2011
    Link to this post
    I have a problem with the page group as well.

    Under the page group i have 4 child pages. They all have the Navigation control configured to show siblings (as a right side menu).

    That works as expected when I view the individual pages. I get a navigation control with the four pages.

    I have set the page group page to select the first child page. When I select the pagegroup in my top menu it shows the content from the first child page - but the navigation control still thinks that it is at the top level.

    I have also tried to change the page type to redirect, but it won't let me select child pages. (There's also another bug - if I try to type the absolute url - it won't let me save the settings. No error is displayed)

    Regards, Dennis
  19. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    28 Apr 2011
    Link to this post
    Hello,

    The behavior of page groups is by design that it would show the content of the first child page. This behavior is such because we have had numerous request to be able to simulate default document as with ASP.NET website. For example if you put a default document for a folder in an ASP.NET webiste and navigate to the url of the folder you will not see default.aspx in the url (similar to home page behavior).

    The problem is with our Navigation control and it is going to be fixed together with the Sitemap refactoring task we have planned for the 4.2 release.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

  20. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    08 Aug 2011
    Link to this post
    Phill,

    I know its been a long time but I finally implemented the code you posted above for the horizontal navigation. and it works beautifully. 

    Thank you so very much!

    Laura
  21. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    02 Sep 2011
    Link to this post
    We have recently upgraded to the latest 4.2 release because of a News error bug that wouldn't allow me to get back into the News section.
    However, with the custom code on this page I now get this error. 

    Above you mentions something about now using Sitemap refactoring.  Is there something different I should be doing?
    Thank you.


    Compiler Error Message: CS0117: 'Telerik.Sitefinity.Web.SiteMapBase' does not contain a definition for 'GetFirstPageDataNode'
     
    Source Error:
     
    Line 41:             if (node.IsGroupPage)
    Line 42:             {
    Line 43:                 SiteMapNode gNode = SiteMapBase.GetFirstPageDataNode(node);
    Line 44:                 e.Item.NavigateUrl = gNode.Url;
    Line 45:             }
  22. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    02 Sep 2011
    Link to this post
    Hello Laura,

    Please use GetActualCurrentNode() instead.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  23. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    05 Dec 2011
    Link to this post
    Finally revisiting this -
    For the top level navigation, I am only getting the Home page (which is not a group page.)
    It doesn't show the page group pages at all in the navigation... ?
    And I am using "Please use GetActualCurrentNode()"

    Any ideas? Thank you.

  24. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Dec 2011
    Link to this post
    Hi Laura,

    Can you post the code that you use for binding the navigation to your databound control?

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  25. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    07 Dec 2011
    Link to this post
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MainMenu.ascx.cs" Inherits="Custom.Navigation.MainMenu" %>
      
      
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
    <telerik:RadMenu ID="RadMenu1" runat="server"
        DataSourceID="SitemapDataSource1"
        EnableEmbeddedBaseStylesheet="true"
        EnableEmbeddedSkins="false"
        EnableOverlay="true"
        EnableScreenBoundaryDetection="false"
        EnableRoundedCorners="false"
        EnableShadows="false"
        DefaultGroupSettings-Width="150"
        CssClass="main-nav"
        >
    </telerik:RadMenu>


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
       
    using Telerik.Sitefinity.Web;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Modules.Pages.Web.UI;
    using Telerik.Web.UI;
    using Telerik.Web.UI.Design;
       
    namespace Custom.Navigation
    {
        [RequireScriptManager]
        public partial class MainMenu : System.Web.UI.UserControl
        {
            string currentLang = "en";
       
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!this.IsDesignMode())
                {
                    this.RadMenu1.ItemDataBound += new Telerik.Web.UI.RadMenuEventHandler(RadMenu1_ItemDataBound);
                }
            }
       
            void RadMenu1_ItemDataBound(object sender, Telerik.Web.UI.RadMenuEventArgs e)
            {
                SiteMapNode cNode = e.Item.DataItem as SiteMapNode;
                PageSiteNode node = (PageSiteNode)cNode;
                // Hide the menu item if set to not show in navigation or if hidden
                if (!node.ShowInNavigation || node.Hidden)
                {
                    e.Item.Visible = false;
                }
       
                // Set group node url to url of first page to fix SF4 Page Group BUG!!!!
                // change GetFirstPageDataNode to GetActualCurrentNode() after 4.2 upgrade
                if (node.IsGroupPage)
                {
                     SiteMapNode gNode = SiteMapBase.GetActualCurrentNode();
                    e.Item.NavigateUrl = gNode.Url;
                }
       
                // Custom Code to support image buttons for the top level menu items
                if (e.Item.Level == 0)
                {
                    SiteMapNode dataItem = e.Item.DataItem as SiteMapNode;
                    if (dataItem != null)
                    {
                        //e.Item.ImageUrl = "~/images/nav/main-" + dataItem.Title.Trim().Replace(" ", "") + "-" + currentLang + "-off.jpg";
                        //e.Item.HoveredImageUrl = "~/images/nav/main-" + dataItem.Title.Trim().Replace(" ", "") + "-" + currentLang + "-on.jpg";
                        //e.Item.Text = "";
       
                    }
                }
                  
                // Set Current Top Level Node to Selected
                SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
                if (currentNode != null)
                {
                    var item = RadMenu1.FindItemByUrl(Page.ResolveUrl(currentNode.Url));
                    if (item != null)
                    {
                        SiteMapNode curItem = item.DataItem as SiteMapNode;
                        if (curItem != null)
                        {
                            if (item.Level == 0)
                            {
                                // Select top level item
                                //item.ImageUrl = "~/images/nav/main-" + curItem.Title.Trim().Replace(" ", "") + "-" + currentLang + "-on.jpg";
                            }
                            else if (item.Level > 0)
                            {
                                // Select top menu item when a sub item is selected
                                GetRootNode(currentNode);
                            }
                        }
                    }
                }
            }
       
            /// <summary>
            /// Calls itself until it gets the section one level below the root
            /// </summary>
            /// <param name="node"></param>
            private void GetRootNode(SiteMapNode node)
            {
                if (node.ParentNode.ParentNode == null)
                {
                    var item = RadMenu1.FindItemByValue(node.Title);
                    if (item != null)
                    {
      
                        //item.ImageUrl = item.HoveredImageUrl;
                    }
                }
                else
                {
                    GetRootNode(node.ParentNode);
                }
       
            }
        }
    }
  26. Roberto
    Roberto avatar
    146 posts
    Registered:
    08 Feb 2008
    07 Dec 2011
    Link to this post
    Hi Laura,

    Dont know if this will help, and i could have completely missed the point, as i thought GetActualCurrentNode was the current page you were on??,  but coudnt you use:

    node.Nodes[0].GetUrl();

    instead of:

    SiteMapNode gNode = SiteMapBase.GetActualCurrentNode();
     
                    e.Item.NavigateUrl = gNode.Url;


26 posts, 0 answered