为什么我的 ASP.NET 母版页不能在内容页中编译?
我正在编写第一个包含母版页的 ASP.NET Web 应用程序。然而,即使我似乎按照书本使用它们,但在运行项目时母版页似乎不起作用。
我创建了一个 Default.MasterPage lite:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Default.master.cs" Inherits="TimeTracker.Default" %>
<!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>My new pager</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<asp:ContentPlaceHolder ID="PageHeader" runat="server">
</asp:ContentPlaceHolder>
</tr>
<tr>
<asp:ContentPlaceHolder ID="Navigation" runat="server">
</asp:ContentPlaceHolder>
</tr>
<tr>
<asp:ContentPlaceHolder ID="Main" runat="server">
</asp:ContentPlaceHolder>
</tr>
<tr>
<asp:ContentPlaceHolder ID="Footer" runat="server">
</asp:ContentPlaceHolder>
</tr>
</table>
</div>
</form>
</body>
</html>
和两个这样的内容页面: (PageHeader.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PageHeader.aspx.cs" Inherits="TimeTracker.PageHeader" MasterPageFile="~/Default.Master" Title="Header"%>
<asp:Content ID="Header" ContentPlaceHolderID="PageHeader" runat="server">
Enalog Time-Tracker
</asp:Content>
和 (Default.aspx)
<%@ Page Language="C#" MasterPageFile="~/Default.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TimeTracker._Default" Title="Login"%>
<asp:Content ID="LoginPage" ContentPlaceHolderID="Main" runat="server">
Login page
</asp:Content>
但是在运行项目时,MasterPage 不会在内容页面中进行编译,即使我相信我已正确连接它们。因此,如果我运行 Default.aspx,我只会看到 ContentPlaceHolderID="Main" 中的内容,如果我运行 PageHeader.aspx,我只会看到 ContentPlaceHolderID="PageHeader" 中的内容。 有谁知道我为什么会出现这种行为,或者我在这里做错了什么? 提前致谢!
I'm writing my first ASP.NET web application containing Master Pages. However, even though I seem to use them by the book, when running the project the Master Pages don't seem to work.
I have created a Default.MasterPage lite this:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Default.master.cs" Inherits="TimeTracker.Default" %>
<!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>My new pager</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<asp:ContentPlaceHolder ID="PageHeader" runat="server">
</asp:ContentPlaceHolder>
</tr>
<tr>
<asp:ContentPlaceHolder ID="Navigation" runat="server">
</asp:ContentPlaceHolder>
</tr>
<tr>
<asp:ContentPlaceHolder ID="Main" runat="server">
</asp:ContentPlaceHolder>
</tr>
<tr>
<asp:ContentPlaceHolder ID="Footer" runat="server">
</asp:ContentPlaceHolder>
</tr>
</table>
</div>
</form>
</body>
</html>
And two content pages like this:
(PageHeader.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PageHeader.aspx.cs" Inherits="TimeTracker.PageHeader" MasterPageFile="~/Default.Master" Title="Header"%>
<asp:Content ID="Header" ContentPlaceHolderID="PageHeader" runat="server">
Enalog Time-Tracker
</asp:Content>
And (Default.aspx)
<%@ Page Language="C#" MasterPageFile="~/Default.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TimeTracker._Default" Title="Login"%>
<asp:Content ID="LoginPage" ContentPlaceHolderID="Main" runat="server">
Login page
</asp:Content>
But when running the project, the MasterPage don't compile in the content pages, even though I believe I've wired them up correctly. So if I for example runs Default.aspx, I only see is the content from the ContentPlaceHolderID="Main", and if I run PageHeader.aspx, I only see the content from the ContentPlaceHolderID="PageHeader".
Do anyone know why I get this behaviour, or perhaps what I'm doing wrong here?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将这两个部分都放在内容页面中,如下所示:
您可能不需要“标题”页面。
You need to put both sections in your content pages, like this:
You probably don't need the "Header" page.
您的母版页不包含任何 标签,因此表格没有任何可显示的内容。
Your master page does not contain any <td> tags, so the tables do not have any displayable content.