1. Default.aspx (主页):
<%@ Page Title="Home" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNamespace._Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" runat="server">
<h2>Welcome to My WebSite</h2>
<p>This is the home page content.</p>
<asp:HyperLink ID="hyperLinkAbout" runat="server" NavigateUrl="~/About.aspx" Text="Learn more about us" />
</asp:Content>
2. About.aspx (关于页面):
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="YourNamespace.About" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" runat="server">
<h2>About Us</h2>
<p>This is the about page content.</p>
</asp:Content>
3. Site.Master (母版页):
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="YourNamespace.Site" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>My WebSite</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="header">
<h1>My WebSite</h1>
<asp:ContentPlaceHolder ID="headerContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="menu">
<ul>
<li><a href="Default.aspx">Home</a></li>
<li><a href="About.aspx">About</a></li>
</ul>
</div>
<div id="mainContent">
<asp:ContentPlaceHolder ID="mainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="footer">
<asp:ContentPlaceHolder ID="footerContent" runat="server">
<p>© 2023 My WebSite. All rights reserved.</p>
</asp:ContentPlaceHolder>
</div>
</div>
</form>
</body>
</html>
在这个简单的示例中,主页 (Default.aspx) 包含欢迎信息和一个链接,链接到关于页面 (About.aspx)。母版页 (Site.master) 定义了整个网站的结构,包括头部、菜单、主要内容区域和页脚。这样,无论用户浏览哪个页面,网站的外观和结构都是一致的。
您可以根据项目的需求和规模扩展这个基本结构,添加更多的页面、功能和交互。
转载请注明出处:http://www.pingtaimeng.com/article/detail/14735/ASP.NET