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

Forums / Sitefinity SDK / Top-parent pagenode of current page

Top-parent pagenode of current page

3 posts, 1 answered
  1. ConsumentenClaim
    ConsumentenClaim avatar
    14 posts
    Registered:
    21 Oct 2010
    15 Mar 2011
    Link to this post
    Hi,

    How can I obtain the "top-parent" / "top-root" of the actual page?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    15 Mar 2011
    Link to this post
    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!
    Answered
  3. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    10 Dec 2012 in reply to Ivan Dimitrov
    Link to this post

    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
3 posts, 1 answered