ASP. NET母版页模板代码
时间: 2023-07-23 18:33:46 浏览: 173
以下是一个简单的ASP.NET母版页模板的代码示例:
```aspx
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="MyWebApp.SiteMaster" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server"></asp:ContentPlaceHolder></title>
</head>
<body>
<form id="form1" runat="server">
<div id="header">
<!-- 头部内容 -->
<asp:ContentPlaceHolder ID="HeaderContent" runat="server"></asp:ContentPlaceHolder>
</div>
<div id="nav">
<!-- 导航内容 -->
<asp:ContentPlaceHolder ID="NavigationContent" runat="server"></asp:ContentPlaceHolder>
</div>
<div id="content">
<!-- 页面内容 -->
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</div>
<div id="footer">
<!-- 底部内容 -->
<asp:ContentPlaceHolder ID="FooterContent" runat="server"></asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
```
在上面的代码中,我们定义了一个Master Page,其中包含了一个头部、导航、内容和底部的区域,这些区域都使用了ContentPlaceHolder控件来占位。在具体的页面中,我们可以使用Content控件来填充这些占位符,例如:
```aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyWebApp._Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h1>Welcome to My Website</h1>
<p>This is the homepage of my website.</p>
</asp:Content>
```
在上面的代码中,我们使用了Content控件来填充Master Page中的MainContent占位符,这样就可以在网站中显示我们定义的内容了。
阅读全文
相关推荐















