Sitefinity Custom Page Title
sitefinity | 2021-02-20
✅ What Are We Trying to Achieve?
The goal is to dynamically modify the browser page title to follow the format:
ABC Inc | (Page_Title)
This ensures better brand visibility and consistent user experience.
🛠️ How to Implement This in a Web Forms Template
Step 1: Ensure the HTML Template Includes the <title>
Tag
Update your Web Forms template (.Master
or .aspx
) by adding a title
tag with an id
attribute for dynamic access:
<html>
<head runat="server">
<title id="page_title"></title>
</head>
<body runat="server">
<p>Lorem Ipsum</p>
</body>
</html>
Step 2: Set Page Title in Page_Load Event
Override the Page_Load
method to dynamically update the page title at runtime:
protected void Page_Load(object sender, EventArgs e)
{
var man = PageManager.GetManager();
if (SiteMapBase.GetActualCurrentNode() != null)
{
try
{
var getCurrentPage = SiteMapBase.GetActualCurrentNode().Id;
if (getCurrentPage != Guid.Empty)
{
page_title.Text = page.Title != null ? string.Format("ABC Inc | {0}", page.Title.ToString()) : "ABC Inc | Apple Balloon Crazy";
}
}
catch (Exception ex)
{
Log.Write("Template ERROR. " + ex.Message + " " + ex.StackTrace);
page_title.Text = "ABC Inc | Apple Balloon Crazy";
}
}
}
⚙️ For MVC Widget (Virtual Page Rendering)
In some cases, especially with MVC widgets used in virtual pages (not physically created in Sitefinity), you must manually update the title directly in the .cshtml
file:
@{
var page = (Page)HttpContext.Current.Handler;
((System.Web.UI.HtmlControls.HtmlTitle)page.Header.FindControl("page_title")).Text = <your_page_title> != null ? string.Format("ABC Inc | {0}", <your_page_title>) : string.Format("{0}", page.Title);
}