views:

41

answers:

2

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?

+1  A: 

Try this in the code behind of the MasterPage:

void MasterPage_PreRender(object sender, EventArgs e)
{
    Page.Title = "Example.com - " + Page.Title;
}
Martin
It doesn't work. Stepping through the code, when executing this line, the Page.Title property is blank
User
Try moving down the page lifecycle of the MasterPage ... is the property blank in the MasterPage_Load ?
Martin
A: 

remove the "runat="server"" but i'm not sure,try it

<head>
    <title>
        Example.com:
        <asp:ContentPlaceHolder ID="PageTitlePlaceHolder" runat="server" />
    </title>
dushouke