Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am certain this question must have been asked before, but I cannot find out how to overcome what appears to be an obvious problem when using master pages in ASP.NET 4.

Since the master page contains the <head/> section of the document, it also contains the title and meta data (e.g. 'description', 'keywords'). Since this data really does need to be specific to each page, how do you set is on a per-page basis instead of inheriting the values in the master page file?

The MSDN information on this does not seem to mention this, but I am sure I read somewhere that this was now possible in ASP.NET 4.

Advice or pointers to relevant information would be very much appreciated.

Best wishes, Patrick

:~
Posted

1 solution

In the master page you can do this:


XML
<head runat="server">
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
</head>


Then in the aspx:

XML
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">
    <asp:Literal ID="TitleLiteral" runat="server" Text="Whatever" />
</asp:Content>



I believe the meta tags can be done in a similar fashion, but you'll need to put the whole tag in the text of the literal.
 
Share this answer
 
Comments
Patrick Skelton 17-Nov-10 13:50pm    
Worked a treat! Thank you very much. - Patrick

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900