我们可以写一个基类,叫basepage.cs,放在app_code目录下,在这个类中,添加一个叫
runtimeMasterPageFile的属性,是一个字符串类型,指定在运行期间才用哪一个模版文件,并且重写OnPreInit
方法,代码如下:
public class BasePage : System.Web.UI.Page
{
private string runtimeMasterPageFile;
public string RuntimeMasterPageFile
{
get
{
return runtimeMasterPageFile;
}
set
{
runtimeMasterPageFile = value;
}
}
protected override void OnPreInit(EventArgs e)
{
if (runtimeMasterPageFile != null)
{
this.MasterPageFile = runtimeMasterPageFile;
}
base.OnPreInit(e);
}
}
接着,我们构造一个叫mainmaster.master的模版页,里面随便搞一个header和footer的信息,中间留一个
叫MainContent的contentplaceholder,然后再建一个叫submaster.master的模版页,其中的
MasterPageFile="~/MainMaster.master",以套用mainmaster模版页,其中放一个一行两列的表格,如下:
<asp:Content ID="foo" ContentPlaceHolderId="MainContent" runat="server">
<table>
<tr>
<td width="300">
Left Column in SubMaster
<br />
<asp:ContentPlaceHolder ID="LeftColumn" runat="server">
</asp:ContentPlaceHolder>
</td>
<td>
&n
| 对此文章发表了评论 |

