Get Page Title and assign that Title to Master page ASP.net

When we use the master pages, create the Page titles, Meta tag dynamically. But in case when we don't want to manage Page titles, Meta tag dynamically for all pages, then how to assign the page title. We guide you here, how you can get the page title and assign to master page title.
 

Master page

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="ArticleMaster.master.cs" Inherits="Masterpages_ArticleMaster" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title><asp:Literal id="litBrowserTitle" runat="server"></asp:Literal> </title>
</head>

AboutUs.aspx
<%@ Page Title="About us" Language="C#" MasterPageFile="~/Masterpages/ArticleMaster.master" AutoEventWireup="true" CodeFile="Aboutus.aspx.cs" Inherits="Aboutus" %>

AboutUs.aspx.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 Aboutus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ((Literal)Master.FindControl("litBrowserTitle")).Text = Page.Title;
    }
}

When you will run the Aboutus.aspx page in browser, then page will render in HTML as:

<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1"><title>About us</title></head>

 


 

Related Alrticles

FREE!!! Registration