+1-888-365-2779
Try Now

Page Title Control

by Gabe Sumner
Publication date:
Sep 1, 2009, 12:25 PM

Version:
1.0

Compatibility:
  • Sitefinity 3.5

Price: $ 0
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!