Master sites with placeholder in head-tag
-
Hi everybody, today i have started to take a look at ASP.NET 2.0. It has some nice features like the new master-sites (waited for something like this). But i've encountered the following problem. Is there a possibility to define a master-site that allows dynamic content inside the head-part? Background is, that my content sites should have different meta tags e.g. for date or keywords. The following code isn't working, but should illustrate what i want to do. Is there some possibility or do i have to look for other solutions? Thanks in advance!
Master site:
Content site:
-
Hi everybody, today i have started to take a look at ASP.NET 2.0. It has some nice features like the new master-sites (waited for something like this). But i've encountered the following problem. Is there a possibility to define a master-site that allows dynamic content inside the head-part? Background is, that my content sites should have different meta tags e.g. for date or keywords. The following code isn't working, but should illustrate what i want to do. Is there some possibility or do i have to look for other solutions? Thanks in advance!
Master site:
Content site:
Hi there, There are two options come to mind: + You can place the
ContentPlaceHolder
control between the open and close tags of the head element in the MasterPage:*************MasterPage.master******************
<%@ Master Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<asp:contentplaceholder id="MetaTagContent" runat="server">
</asp:contentplaceholder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="MainContent" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>*************ContentPage.aspx******************
<%@ Page Language="C#" MasterPageFile="~/MyMasterPage.master" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MetaTagContent" Runat="Server">
<meta name="date" content="2004-12-01T" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<h3>This is the main content</h3>
</asp:Content>+ You can programmatically add the the meta tag in the content page using the Page.Header[^] property.
-
Hi there, There are two options come to mind: + You can place the
ContentPlaceHolder
control between the open and close tags of the head element in the MasterPage:*************MasterPage.master******************
<%@ Master Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<asp:contentplaceholder id="MetaTagContent" runat="server">
</asp:contentplaceholder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="MainContent" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>*************ContentPage.aspx******************
<%@ Page Language="C#" MasterPageFile="~/MyMasterPage.master" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MetaTagContent" Runat="Server">
<meta name="date" content="2004-12-01T" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<h3>This is the main content</h3>
</asp:Content>+ You can programmatically add the the meta tag in the content page using the Page.Header[^] property.
Thanks for the reply. I tried the first option before posting here, but it doesn't work (get a compiler error that the tag prefix asp is unknown). Second option isn't as nice as the first one would be, but it does what i want.
-
Thanks for the reply. I tried the first option before posting here, but it doesn't work (get a compiler error that the tag prefix asp is unknown). Second option isn't as nice as the first one would be, but it does what i want.
Stefan Troschütz wrote:
tried the first option before posting here, but it doesn't work (get a compiler error that the tag prefix asp is unknown).
Don't worry about this error, it still works just fine, make sure that you don't have any other error when the build is OK when you compile your web site.