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

Forums / General Discussions / How to get current page title?

How to get current page title?

20 posts, 1 answered
  1. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    15 Mar 2011
    Link to this post
    How can I get the current pageNode and access its properties?
  2. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    15 Mar 2011
    Link to this post
    Hi Bruno,

    Here's one way of doing it. I have this code in a UserControl that I drop onto my Master Template so that each page gets a Page title. Just so my clients (content editors) don't get confused when creating content and try to add a title themselves I have it setup so that when the page is in design/edit mode it displays a place holder message.

    PageTitle.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PageTitle.ascx.cs" Inherits="theme_controls_content_PageTitle" %>
    <asp:Literal ID="lblPageTitle" runat="server" />

    PageTitle.ascx.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    using Telerik.Sitefinity.Web;
    using Telerik.Sitefinity.Modules.Pages;
     
    public partial class theme_controls_content_PageTitle : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (!this.IsDesignMode())
                {
                    string title = new PageManager().GetPageNode(new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key)).Title;
                    if (title != "")
                        lblPageTitle.Text = title;
                }
                else
                {
                    lblPageTitle.Text = "Page Title automatically inserted.";
                }
            }
        }
    }

    Hope that helps.

    Cheers,
    Phill
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    16 Mar 2011
    Link to this post
    Hello ,

    You should better use SiteMapBase.GetActualCurrentNode() and from there get a reference to the PageNode object.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Answered
  4. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    16 Mar 2011
    Link to this post
    Good point Ivan, I had created that code during Beta/RC, before GetActualCurrentNode() existed. I also only ever use custom menus that fix the menu item Group bug by assigning a group item the same url as the first node so the code i provided always works as expected.

    But yes, I would recommend changing the retrieval of the title to:
    string title = SiteMapBase.GetActualCurrentNode().Title;

    Regards,
    Phill
  5. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    05 Apr 2011
    Link to this post
    Hi,

    Is there a way for me to get the page Revision number from code?

    Thanks,
    Andrei
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    05 Apr 2011
    Link to this post
    Hi Andrei,

    Do you mean the page Version? If so there is a public property of the content object - Version that you can use.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

  7. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    05 Apr 2011
    Link to this post
    Ivan,

    Yes, I meant the page version, sorry. I am just trying to find in the forums the line of code that
    I need. I am still learning the API and so am unsure how to get to it.

    I am looking for something like "string version = Page.CurrentPage.Version;" or something like that.

    Many thanks,
    Andrei
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    05 Apr 2011
    Link to this post
    Hello Andrei,

    The GetActualCurrentNode returns PageSiteNode. You can call GetPageNode of the page manager and get the version


                var m= PageManager.GetManager();
                var s = m.GetPageNode(PageSiteNode.Id);
                var version = s.Page.Version;

    Best wishes,
    Ivan Dimitrov
    the Telerik team

  9. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    05 Apr 2011
    Link to this post
    Ivan,

    That is wonderful, thanks. I will give it a go.

    Many thanks,
    Andrei
  10. Anatoliy Gerasin
    Anatoliy Gerasin avatar
    27 posts
    Registered:
    17 May 2010
    06 Apr 2011
    Link to this post
    So, I have a user widget with public property with default value described in constructor.
    This default value must be current page name.
    Both
    pageTitle = new PageManager().GetPageNode(new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key)).Title
    and
    pageTitle = SiteMapBase.GetActualCurrentNode().Title
    is working until I click "Edit" link for this widget.
    Seems that Edit window asks my widget and pageTitle is being calculated again. But I see that SiteMapBase.GetActualCurrentNode() and SiteMapBase.GetCurrentProvider().CurrentNode are null. Probably because SiteMapBase.GetCurrentProvider() is of type  BackendSiteMap. How can I get SitefinitySiteMap in this case and will it help me to get current page title?
  11. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    10 Apr 2011
    Link to this post
    Hello Anatoliy Gerasin,

    The actual page during page edit mode is not the page that you are editing. The SiteMap provider used in the front end is returning null because the page is not part of this provider. You can try using ths.Page.Title to get the title.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

  12. Anatoliy Gerasin
    Anatoliy Gerasin avatar
    27 posts
    Registered:
    17 May 2010
    11 Apr 2011
    Link to this post
    And there is no way to get content page title in Edit modal window in any context, is there?
  13. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Apr 2011
    Link to this post
    Hello Anatoliy Gerasin,

    Can you please elaborate a little bit on the scenario. Are you editing the page in the page editor or you are using browse and edit?

    Best wishes,
    Radoslav Georgiev
    the Telerik team

  14. Anatoliy Gerasin
    Anatoliy Gerasin avatar
    27 posts
    Registered:
    17 May 2010
    14 Apr 2011
    Link to this post
    There is a case I tried just now:
    - Create new custom widget "MyWidget".
    - Add property "PageUrl" with default value calculated as described above (with node calculation).
    - Add label "MyLabel" and fill it with PageUrl value.
    - Create new page "test-page" with URL "/test-page" and go to editing this page.
    - Drag and drop "MyWidget" in the edit window.
    - I see that Label shows "test-page"
    - Then I click "Edit" link on dropped "MyWidget"
    - I see Edit window and see "MyLabel" equals empty string. But I would like to get "test-page" string in this case.

    However I discovered that HttpContext.Current.Request.UrlReferrer = "/test-page/Action/Edit" in Edit window. Therefore I could check if I can get page url from CurrentNode - and if not - then parse UrlReferrer with regular expression.
    This is a workaround but I confused to use it - is there more "civilized" solution?
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    14 Apr 2011
    Link to this post
    Hello Anatoliy,

    When you edit your widget you can call Context.Request.QueryString["PageId"]. This should give you the page ID,so you can pass it to the PageManager. You can add the code inside your control designer - InitializeControls

    Regards,
    Ivan Dimitrov
    the Telerik team

  16. Augus
    Augus avatar
    34 posts
    Registered:
    29 Mar 2011
    29 Apr 2011
    Link to this post
    hi Ivan, i'm doing as you suggested but i always get the wrong pageId, and always get this error "You are trying to access item that no longer exists. The most probable reason is that it has been deleted by another user."

    string pageId = Context.Request.QueryString["PageId"];
     
                if (!String.IsNullOrEmpty(pageId))
                {
                    var pManager = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager();
                    PageNode page = pManager.GetPageNode(new Guid(pageId)); //exception happen here
                }

    i'm guessing it returning the edit mode page not the actual page. any input how to solve this?
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    29 Apr 2011
    Link to this post
    Hi Anatoliy,

    Use GetPageDraft because this is the draft version of a page. Then you can get the PageData from ParentPage property.

    All the best,
    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
  18. Matt
    Matt avatar
    14 posts
    Registered:
    25 Jan 2012
    09 May 2012
    Link to this post
    Hi Ivan,

    I have a question regarding GetActualCurrentNode(). I have a blog on my site which uses a specific detail page to show the individual entries.  If I were to use this method on that template page, would it return a PageSiteNode that describes the post page (this is what I assume will happen), or will it describe the blog post as though it were its own page. What I mean is if I check the Id of the returned PageSiteNode, will it be the id of the blog post page or the id of the individual blog post?

    I am currently migrating to Sitefinity 5 and am updating old 3.X code. I need a way to, from the blog post detail page, get the id of the specific blog post the user has navigated to.

    Thank you!

  19. Matt
    Matt avatar
    14 posts
    Registered:
    25 Jan 2012
    09 May 2012
    Link to this post
    Gah, I got a server error then pressed back and resubmitted and it double posted. Apologies, you can delete this one.

    Thanks
  20. Matt
    Matt avatar
    14 posts
    Registered:
    25 Jan 2012
    15 May 2012
    Link to this post
    For anyone who might also be wondering how to get the current BlogPost object from a dedicated blog post detail page, here is the code straight from Telerik:

    string urlParams = this.GetUrlParameterString(true);
    if (urlParams != null)
    {
        BlogsManager blogsManager = BlogsManager.GetManager();
        string redirectUrl;
        var item = blogsManager.GetItemFromUrl(typeof(BlogPost), urlParams, true, out redirectUrl);
    }

    Thanks
20 posts, 1 answered