Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用母版页和内容占位符创建子标题_Asp.net_Master Pages_Contentplaceholder - Fatal编程技术网

Asp.net 使用母版页和内容占位符创建子标题

Asp.net 使用母版页和内容占位符创建子标题,asp.net,master-pages,contentplaceholder,Asp.net,Master Pages,Contentplaceholder,我有一个只有几页的网站,我希望这些页面的标题是: Foo - 1st Page Foo - 2nd Page Foo - 3rd Page 我已使用以下代码创建了母版页: <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Foo.master.cs" Inherits="Foo" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E

我有一个只有几页的网站,我希望这些页面的标题是:

Foo - 1st Page
Foo - 2nd Page
Foo - 3rd Page
我已使用以下代码创建了母版页:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Foo.master.cs" Inherits="Foo" %>

<!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>Foo - <asp:ContentPlaceHolder ID="SubTitle" runat="server"></asp:ContentPlaceHolder></title>
</head>
<body>
    <asp:ContentPlaceHolder ID="MainContent" runat="server">
    </asp:ContentPlaceHolder>
</body>
</html>

我做错了什么?

原来这个问题已经被问到了:


在阅读了那里的答案后,我发现从母版页的
元素中删除
runat=“server”
成功了。

您不想从
中删除
runat=“server”
;这会造成其他问题

使用以下方法,这是Visual Studio 2012中ASP.Net Web窗体应用程序中的默认方法

<!-- Master Page -->
<head runat="server">
    <title>Foo - <%: Page.Title %></title>
</head>

<!-- Content Page/xxx.aspx -->
<%@ Page Title="Home Page" ...>

富-

您认为生成的标记是什么?(无论如何,对我来说,这是一个不寻常的占位符用法。)我想知道一个更好的解决方案是否是在代码中设置页面的Title属性。@ThatBlairGuy-我在我的问题中添加了html源代码。Visual Studio的母版页模板在母版页的标题标记中有一个名为
title
的内容占位符。我刚刚在它前面添加了
Foo-
文本,并将其重命名为
SubTitle
。非常好。非常感谢。就我而言,缺少
runat=“server”
不会导致问题(这只是一小部分测试页面,在
标题中没有其他内容),但我采纳了您的建议,因为它使代码更简单。
<!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><title>
  1st Page
</title></head>
<body>

<a href="Page2.aspx">Page 2</a>

</body>
</html>
<!-- Master Page -->
<head runat="server">
    <title>Foo - <%: Page.Title %></title>
</head>

<!-- Content Page/xxx.aspx -->
<%@ Page Title="Home Page" ...>