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

Forums / Developing with Sitefinity / Change Page TItle

Change Page TItle

20 posts, 1 answered
  1. Peppi Alexandrova
    Peppi Alexandrova avatar
    14 posts
    Registered:
    22 Feb 2006
    29 Jun 2010
    Link to this post
    Dear Sirs,
    is there a way to programmatically change the Page Title ( I mean the <head><title>).
    We need to dynamically change it in the code and not use the default Title in sitefinity admin,

    Thanks,
    Penka
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jun 2010
    Link to this post
    Hello Peppi Alexandrova,

    You can create a custom class that inherits from InternalPage and override SetTitle(ICmsPage page). The method sets the Title of the current page.

    sample

    public class InternalPageCustom : InternalPage
    {
        public InternalPageCustom()
        {
        }
      
        protected override void SetTitle(Telerik.Cms.ICmsPage page)
        {
            //base.SetTitle(page);
            this.Title = "somevalue";
        }
    }

    Then you have to replace the default InternalPage with the custom one inside Sitefinity/cmsentrypoint.aspx

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Peppi Alexandrova
    Peppi Alexandrova avatar
    14 posts
    Registered:
    22 Feb 2006
    29 Jun 2010
    Link to this post
    Works great!
    Many thanks for prompt reply, Ivan.

    Regards,
    Penka
  4. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    16 Mar 2011
    Link to this post
    Is it safe to assume that when you say: "Then you have to replace the default InternalPage with the custom one inside Sitefinity/cmsentrypoint.aspx" you mean that you should change the Inherits attribute of the Page directive of the cmsentrypoint.aspx file. Is that correct?

    <%@ Page Inherits="Telerik.Cms.Web.InternalPageCustom" MasterPageFile="~/Sitefinity/Dummy.master" %>

    And to use this how do we access it from custom controls?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Mar 2011
    Link to this post
    Hi J.Hoventer,

    If you do not replace the default internal page, then the changes from the custom class will not apply. You have to change the inherits attribute of the cmsentrypoint page, so the custom class will be called.

    Best wishes,
    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!
  6. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    16 Mar 2011
    Link to this post
    Great that answers the first question, but what about the second question?

    How do we access that classes properties/methods from a custom control that we're building?

  7. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    16 Mar 2011
    Link to this post
    In this method that is created in your suggested custom class:
    protected override void SetTitle(Telerik.Cms.ICmsPage page)
        {
            //base.SetTitle(page);
            this.Title = "somevalue";
        }

    What calls the SetTitle method?

    We've implemented the class and replaced the cmsentrypoint.aspx Inherits attribute in the page directive with our new class name and it's working. Every page title is now 'somevalue'.

    1. How do manually call this method to provide our own title "when needed"?
    2. How do we have this method use the default page title when we "don't need manual page titles"?

    Regards,
    Jacques
  8. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    16 Mar 2011
    Link to this post
    Ok one step further, but I seriously don't see how this could work.

    You can gain access to the new custom file by doing the following in a user control:
    ((MyCustomInternalPage)this.Page)

    So we could potentially add methods to that class to change the title, but it won't work, because the SetTitle method is being called very early on in the page life cycle... before the Page_Load of the User Control.

    So the question remains: I don't see how this custom control would allow you to change the title of the page at runtime. This must be possible though since the Blog and News modules manage to do it?
  9. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    16 Mar 2011
    Link to this post
    Anyone seeing my questions?
  10. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    17 Mar 2011
    Link to this post
    Anyone?
  11. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    25 Mar 2011
    Link to this post
    The answers are getting fewer and fewer these days. What's happening to Telerik/Sitefinity?
  12. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    25 Mar 2011
    Link to this post
    InternalPage has a SetTitle method but no SetDescription or SetKeywords... where can we get a hold of those methods?
  13. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    25 Mar 2011
    Link to this post
    It's not even those methods we're looking for it's the property this.Title that does exist, but we're looking for this.Description and this.Keywords...?
  14. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    25 Mar 2011
    Link to this post
    Does anyone other than Telerik staff actually respond on these forums?

    Does anyone know of another forum for Sitefinity, the answers on Sitefinity.com are getting fewer and fewer.

  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Mar 2011
    Link to this post
    Hi J.Hoventer,

    The ICmsPage properties could be injected in CreateChildControls

    protected override void CreateChildControls()
            {
                ICmsPage cmsPage = base.CmsPage;

                this.SetTitle(cmsPage);

                if (!String.IsNullOrEmpty(cmsPage.Description))
                    this.Header.Controls.Add(CmsHelper.CreateMeta("Description", cmsPage.Description));

                if (!String.IsNullOrEmpty(cmsPage.Keywords))
                    this.Header.Controls.Add(CmsHelper.CreateMeta("Keywords", cmsPage.Keywords));
           }


    Greetings,
    Ivan Dimitrov
    the Telerik team
  16. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    25 Mar 2011
    Link to this post
    Will this not create a duplicate Description meta tag?
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Mar 2011
    Link to this post
    Hi J.Hoventer,

    If you do not call the base, there will not be other tags. If you call the base you have to remove the base tags with another portion of code - C# Inheritance

    All the best,
    Ivan Dimitrov
    the Telerik team
  18. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    28 Mar 2011
    Link to this post
    This is a very odd suggestion you have provided. Without calling base.CreateChildControls you loose everything else on the page.

    Why would you suggest something like that?
  19. Roland
    Roland avatar
    6 posts
    Registered:
    04 Feb 2011
    09 Feb 2012
    Link to this post
    Hey,

    I know this is somewhat of an old post, but I wanted to share how I figured this out.
    I created a custom control as a separate library (not the aspx controls you just reference).

    Then, in my class:

    public class BlogPosts : SimpleView
    {
            ... // I added the following
            protected override void OnPreRender(EventArgs e)
            {
                this.Page.Title = "Hello World";
                base.OnPreRender(e);
            }
    }
  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Feb 2012
    Link to this post
    Hello,

    The best way to do this is through InternalPage which has a method SetTitle. In your case you are making an additional call which might result in performance in some cases.

    Regards,
    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
Register for webinar
20 posts, 1 answered