Top-parent pagenode of current page - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Top-parent pagenode of current page

  • Top-parent pagenode of current page
  • Hi,

    How can I obtain the "top-parent" / "top-root" of the actual page?
  • Hello ,

    You can use while loop to get the top level parent

    var actualNode = SiteMapBase.GetActualCurrentNode();
    while (actualNode.ParentNode != null)
        actualNode = actualNode.ParentNode as PageSiteNode;
     


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

  • using
    Telerik.Sitefinity.Web;
     
     
     
     
    namespace SitefinityWebApp.UserControls
        public partial class SubNaviTitle : System.Web.UI.UserControl
        
            protected void Page_Load(object sender, EventArgs e)
            
                var actualNode = SiteMapBase.GetActualCurrentNode();
                while (actualNode.ParentNode != null && actualNode.ParentNode.Title != "Pages")
                
                    actualNode = actualNode.ParentNode as PageSiteNode;
     
                
                         Label1.Text = actualNode.Title;
            
        

    I had the problem that Ivans Code returned 'Pages¨avbove changes fixed that for me.

    Same for 

            Label1.Text =  SiteMapBase.GetActualCurrentNode().RootNode.Title

    Which would be the shortest version, but also returns Pages.

    Markus