+1-888-365-2779
Try Now

Custom Page Title Control

by Mustafa Kipergil
Publication date:
Nov 12, 2009, 23:43 PM

Version:
1.0

Compatibility:
  • Sitefinity 3.7
  • Sitefinity 3.6

Price: $ 0
Custom Page Title Control is a modified version of Gabe Sumner's Page Title Control. Sometimes I need to override the existing page title of my pages with a custom text so, I modified Gabe's control a little bit. Please, refer to Gabe's Page Title Control for usage instructions.

Here is my version of the control:

pagetitle.ascx 

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PageTitle.ascx.cs" Inherits="UserControls_box_PageTitle" %>  
  
<h2 class="pageTitle">  
    <asp:Label ID="lblTitle" runat="server" Text=""></asp:Label>  
</h2>  
 

pagetitle.ascx.cs

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
  
public partial class UserControls_box_PageTitle : System.Web.UI.UserControl  
{  
  
    //You can override the page title if you enter any text from usercontrol options.  
    private string text = "";  
    public string Text  
    {  
        get { return text; }  
        set { text = value; }  
    }  
  
    protected void Page_Load(object sender, EventArgs e)  
    {  
            LoadTitle();  
    }  
  
    private void LoadTitle()  
    {  
        try  
        {  
            if (!string.IsNullOrEmpty(this.Text))  
            {  
                lblTitle.Text = this.Text;  
            }  
            else  
            {  
                Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();  
                Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;  
                Telerik.Cms.ICmsPage currentPage = currentNode.CmsPage;  
                if (currentPage != null)  
                {  
                    lblTitle.Text = currentPage.Title;  
                }  
            }  
        }  
        catch (Exception)  
        {  
               
        }  
    }  
}