My master page looks like:
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="PageTitlePlaceHolder" runat="server" />
</title>
Content pages look like:
<asp:Content ID="TitleContent1"
ContentPlaceHolderID="PageTitlePlaceHolder" runat="Server">
My Page
</asp:Content>
This works by placing the content page specific title on the page ("My Page" in this example). Now I want to add a global prefix to the title in my master page for the site name. So I want:
<head runat="server">
<title>
Example.com:
<asp:ContentPlaceHolder ID="PageTitlePlaceHolder" runat="server" />
</title>
However, when I do this content pages are still rendered without "Example.com" in the tile, it's like it's ignored.
Why is this happening and how can I achieve this?
The work around I found most acceptable is to use multiple
ContentPlaceHolder
controls.Note that any other content inside
<title>
, including whitespace, is stripped away. Any spacing between theContentPlaceHolder
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.Try this in the code behind of the MasterPage:
in the master Page, Put
where websitename.com is the domain name of the website.
and then in Each Content page , put a title.
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:
remove the "runat="server"" but i'm not sure,try it
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.