We are aware that the <header> and <body> tags are contained in the Master page. Only the contents come in content pages.
One question that might arise is that how would the title change along with the change in content pages?
One workaround to do it is, provide a <ContentPlaceHolder> control inside the header of the master page. In the content page write the <title> tag.
Master page content would look like this.
<link href=”~/Styles/Site.css” rel=”stylesheet” type=”text/css” />
<asp:ContentPlaceHolder ID=”HeadContent” runat=”server”>
Content page would look like this.
<asp:Content ID=”HeaderContent” runat=”server” ContentPlaceHolderID=”HeadContent”>
<title>Title from the content page</title>
While running the application, you can see the “Title from the content page” in the content page.
Well, this is just a work around. There is a clear and straight solution provided by ASP.Net for this.
To change the title, use the title property of page directives (in the content pages).
<%@ Page Language=”C#” Title=”Title from the content page” MasterPageFile=”~/Site.master” AutoEventWireup=”true”
CodeBehind=”DataEntry.aspx.cs” Inherits=”MasterPageExploration._Default” %>
When the Asp.Net sees the title property, it renders it for your page.
Well, the next question.
What would happen if the <title> element is found in the master page itself? Is it legal to have it in the master/content page and provide the title element on the page directive?
Here is the hierarchy of search, where the first holds the least priority and the last box holds the top priority.
However it is ideal/advised to keep the title element in the master page blank (or with a default site name), and provide the dynamic titles in each content page in the title property of the page directive.