views:

528

answers:

2

This is what I have in the aspx page:

<head runat="server">
    <title>Website - <asp:ContentPlaceHolder ID="HeadContent" runat="server" /></title>
</head>

This is what's in the view:

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    Homepage
</asp:Content>

For some reason, this HTML is generated:

<title>Homepage</title>

The 'Website - ' part is getting removed. Anybody know how I can fix this?

A: 

could you do something like this?

<head runat="server">
    <asp:ContentPlaceHolder ID="HeadContent" runat="server"><title>Website</title></asp:ContentPlaceHolder >
</head>

and then override the whole title string in your view?

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title>Homepage</title>
</asp:Content>
Nick
I could, but what I'd like to do is set the first part just once. Let's say in the future, I want to change the title from 'Website - Homepage' to 'New Website - Homepage'. Instead of changing it in every view, all I'd have to do is modify the master page.
Daniel T.
+4  A: 

Phil Haack has an explanation of this issue (and a work-around) at http://haacked.com/archive/2009/04/03/tipjar-title-tags-and-master-pages.aspx . The work-around is that you use an asp:LiteralControl for the static part of your page title.

laurie
Thanks, that did the trick.
Daniel T.