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

Forums / Developing with Sitefinity / Page title of news detail view

Page title of news detail view

4 posts, 0 answered
  1. Florian
    Florian avatar
    17 posts
    Registered:
    08 Aug 2008
    13 Apr 2009
    Link to this post
    Hi guys,

    I am looking for a way to print the page title on every page. It's working great for any "normal" cms page, but how can I read out the page title of a detail view of a news item? Here my code (I made a switch for a page, which is a detail page of a news entry, what do I have to put in instead of "???.."):

    1                 if (Telerik.CmsContext.CurrentUrl.ToString().Equals("Telerik.Cms.Web.CachedUrlRewriteServiceContext"))  
    2                 {  
    3                     l.Add(Telerik.CmsContext.CurrentUrl.GetSiteMapNode());  
    4                     PageTitle.Text = "???????" ;  
    5                 }  
    6                 else 
    7                 {  
    8                     PageTitle.Text = Telerik.CmsContext.CurrentUrl.ToString();  
    9                 } 

    Thanks and regards

    Flo
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    15 Apr 2009
    Link to this post
    Hi Florian,

    If I understand you correctly, you want to take the page title on every page, having a detailed News article item. This Title is dynamically created by the NewsView control and its settings:
    • PageTitleFormatString, which by default is set to > {0}
    • PageTitleMetaFields, which by default is set to Title
    • PageTitleMode, which by default is set to Append.
    So, the Page title is being generated with PageTitle > NewsItemTitle.

    You can take the final title (let's call it this way) a bit different approach than the common this.Page.Title;

    Every control has its own lifecycle and Page_Load event, in which you most probably try to take the Title. So, here is what happens:
    1. The page is being rendered with the default Title set by the CMS.
    2. Your Control takes the current page title.
    3. The NewsView control tweaks the Title. So your Title string in step 2 is an obsolete one.

    Possible solutions:
    1. Place your control *after* the NewsView control, so you take the actual page title;
    2. Use the following code:
        protected override void OnInit(EventArgs e) 
        { 
            base.OnInit(e); 
            this.Page.PreRenderComplete += new EventHandler(Page_PreRenderComplete); 
        } 
     
        void Page_PreRenderComplete(object sender, EventArgs e) 
        { 
            string finaltitle = this.Page.Title; 
        } 
     

    This should be in user control. Here is how it works:
    1. The page title is set with its value;
    2. You hook up to the PreRenderComplete event, which occurs for all controls on the page.
    3. Everytime a control is rendered (which means all processing events are over), we take the Page Title.
    4. Generally, with this approach we take the last change, but are losing the previous. Well, this is what we want actually.

    I hope this makes sense. Let me know if you need any further help, or if I am missing something.
    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Shaka
    Shaka avatar
    11 posts
    Registered:
    07 Jan 2011
    23 Apr 2011
    Link to this post
    How can I generate the title with just the PageTitle and not the  NewsItemTitle?

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Apr 2011
    Link to this post
    Hello Shaka,

    You can achieve this by overriding SetTitle method of the InternalPage class.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

Register for webinar
4 posts, 0 answered