Add-ons

Page Title Control

by Gabe Sumner (Sitefinity Team)
Updated on: September 1, 2009 | 24699 views

Compatibility: Version 3.5
Version: 1.0
Tags: Other , Free
Control that simply outputs the page's title. This prevents you from having to manually enter the page's title via a Generic Control. Terms Of Use

Download from Publisher
FREE
While working through my Sitefinity web site it became obvious that I wanted every page to start with "breadcrumbs", followed by the page's title.

The "breadcrumbs" are easily accomplished by dragging Sitefinity's"Breadcrumb" Navigation control onto my templates.  By applying the"breadcrumb" control to my templates, rather than individual pages, it ensures that the control gets applied to ALL pages. 

For page title, however, I was finding that I needed to use a "GenericContent" control on each individual page.  This was also forcing me to manually type the page's title (something that I had already typed when creating the original page) on each page.

There is really no need to manually type your page's title though.  With just a few lines of code you can create a "Page Title" control that you can drag & drop onto your page template.  Here is how it's done:

~/GoonDocks/UserControls/PageTitle.aspx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PageTitle.ascx.cs" Inherits="GoonDocks_UserControls_PageTitle" %>  
<h1><asp:Label ID="pageTitle" runat="server" /></h1

 

 

 

 ~/GoonDocks/UserControls/PageTitle.aspx.cs

 

using System;   
using System.Web;   
using System.Web.UI.WebControls;   
using Telerik.Cms.Web;   
  
public partial class GoonDocks_UserControls_PageTitle : System.Web.UI.UserControl   
{   
    protected void Page_Load(object sender, EventArgs e)   
    {   
        CmsSiteMapNode CurrentCmsNode = (CmsSiteMapNode)SiteMap.CurrentNode;   
  
        if (CurrentCmsNode != null)   
        {   
            pageTitle.Text = CurrentCmsNode.CmsPage.Title;   
        }   
        else  
        {   
            pageTitle.Text = "Page Title";   
        }   
    }   
}  

 

Then you just have to add your control mapping in the <toolboxControls> section of your web.config:

 

<add name="Page Title" section="GoonDocks" url="~/GoonDocks/UserControls/PageTitle.ascx" /> 

 

The page title that gets used is the title that you typed for the "Head Content" when creating the page.

Piece of cake!  You can now drag & drop this "Page Title" control onto any of your pages or your template.  Wherever your control is placed it will result in the page's title being displayed!


3 comments

  • J 30 Sep 2009
    02:53 PM
    Very helpful, thanks :)
  • Laura 04 Nov 2009
    04:01 PM
    What if I watned to get the Menu Name instead of the Page Title. In case for the Title I want to add extra words such as the company name, etc.
    Great stuff as always though by the way!
  • Mark 18 Apr 2011
    03:46 PM
    Can this be updated for 4.0? Please?

Add Comment

  • Providing an email will subscribe you for receving comment notifications.

  •