//关于ASP.NET动态加载Master页面
//首先创建一母版页Master.master
/*
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Master.master.cs" Inherits="Master" %>
<!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></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<span>Master is using..</span>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
*/
//创建一内容页面,去掉内容页面所有的所有的HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content runat="server" ID="ct" ContentPlaceHolderID="ContentPlaceHolder1">
<asp:Label runat="server" ID="dd">This is a test!!</asp:Label>
</asp:Content>
//创建一个基础页面
/// <summary>
///BasePage 的摘要说明
/// </summary>
public class BasePage:System.Web.UI.Page
{
public BasePage()
{
//
//TODO: 在此处添加构造函数逻辑
//
this.PreInit += new EventHandler(BasePage_PreInit);
}
//母板页面的载入是在PreInit事件中的
void BasePage_PreInit(object sender, EventArgs e)
{
MasterPageFile = "~/Master.master";
}
}
//最后在内容页面的类中继承基础类
public partial class Default2:BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}