ASP.NET: Having Common Page Title In Master Page With Each Page Adding Page-specific Title?
Solution 1:
Try this in the code behind of the MasterPage:
void MasterPage_PreRender(object sender, EventArgs e)
{
Page.Title = "Example.com - " + Page.Title;
}
Solution 2:
Remove the title tag from the master page and use the code Martin provided. Now in your content pages set the title in the Page tag at the top of the file like so:
<%@ Page ... Title="Contact" %>
Solution 3:
The work around I found most acceptable is to use multiple ContentPlaceHolder
controls.
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="cphMasterTitle" runat="server">Example.com: </asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="cphSubtitle" runat="server" />
</title>
</head>
Note that any other content inside <title>
, including whitespace, is stripped away. Any spacing between the ContentPlaceHolder
content needs to be done inside the controls.
I've also used <asp:Literal runat="server">Example.com: </asp:Literal>
when I don't want to expose a placeholder to the content pages.
Solution 4:
remove the "runat="server"" but i'm not sure,try it
<head>
<title>
Example.com:
<asp:ContentPlaceHolder ID="PageTitlePlaceHolder" runat="server" />
</title>
Solution 5:
Two options.
one is remove runat=server
from <head>
(jefferydu)
Two is using the Page.Title as string. (Martin)
I prefer to use a object I wrote somewhere that add also Title for facebook, description for search engines, etc for any page I used. This object stores the page title in three strings- one before, one is page title, one after.
Post a Comment for "ASP.NET: Having Common Page Title In Master Page With Each Page Adding Page-specific Title?"