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

Forums / Developing with Sitefinity / automatic link back to parent

automatic link back to parent

7 posts, 0 answered
  1. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    26 Jan 2010
    Link to this post
    Does anyone out there have a control/code that will ... when placed on a page, will create a link back to its parent page?  So as to not hard code the link, (espcially if pages get moved or file names change).

    It would be placed on sub-pages in the site where there is no other navigation on the page to it's parent.  I will make this a styled div tag with a background button image and this link, so it can just be place on any page without having to actually choose the destination page.

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    26 Jan 2010
    Link to this post
    Hi Laura,

    You can use cmsPage object and its Parent property cmsPage.Parent - this is our page parent.  By doing so you get only the current page and you do not have to know even which is the parent.

    Kind regards,
    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. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    28 Jan 2010
    Link to this post
    what is the difference between this
    Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();     
    Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;     
    Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;
     
    and this
    SiteMapNode node = SiteMap.CurrentNode;
     

    and which one should I use for the example below?

    For a control to drop onto a page to basically write the page URL directly above the current page.

    <a href="i_am_this_pages_parent.aspx"">Go Back</a>

    Thank you.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    28 Jan 2010
    Link to this post
    Hi Laura,

    The first code casts SiteMap node to CmsSiteMapNode, the second code just uses SiteMap node.You should better use CmsSiteMap node and get its parent url.

    Sincerely yours,
    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.
  5. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    28 Jan 2010
    Link to this post
    Thank you...  I know this is basic stuff but maybe not for me :)

    on the control - should I have

    <

     

    asp:LinkButton id="BackButtonLink" runat="server" class="btnLinkText" text="Back"></asp:LinkButton>

     


    And in the code

    BackButtonLink.Attributes.Add  

    ???   currentPage.Parent.StaticUrl  

    sorry... i just can't find the exact code anywhere on my own.

     

  6. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    28 Jan 2010
    Link to this post
    Or should I just use a literal and write out the <a href=".... ?
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    29 Jan 2010
    Link to this post
    Hello Laura,

    Below you can find a sample code that gets the current page and sets PostBackUrl of a Button control to the parent of this page.

    Button b = new Button();
    ICmsUrlContext pageID = (ICmsUrlContext)this.Context.Items[Telerik.Cms.Web.UrlHelper.CmsPageKey];
    Guid pID = pageID.PageID;
    var cmsManager1 = new CmsManager();
    ICmsPage p = (ICmsPage)cmsManager1.GetPage(pID);
    if (p.Parent != null)
    {
        b.PostBackUrl = p.Parent.StaticUrl;
        b.Text = "Back to parent";
    }
    Controls.Add(b);


    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.
Register for webinar
7 posts, 0 answered