【发布时间】:2012-02-06 16:48:00
【问题描述】:
我有一个最初继承自 MastePage.master 的页面。我想在我的项目的其他地方使用相同的页面,但使用不同的母版页(MasterPage2.master)。为此,我使用以下代码。
private void Page_PreInit(object sender, EventArgs e)
{
if (Request.QueryString["Update"].ToString() == "New")
{
this.MasterPageFile = "MasterPage2.master";
Content con = new Content();
con = (Content)this.FindControl("Content1");
this.Content1.ContentPlaceHolderID = "ContentPlaceHolder2";
}
}
我还尝试将 asp 内容标签的 ContentPlaceHolderID 设置为来自 MasterPage2.master 的 ContentPlaceHolder2。最初是 ContentPlaceHolder1。
但我在 con = (Content)this.FindControl("Content1"); 处得到空值;
谢谢
【问题讨论】:
-
顺便说一下,页面不会“继承”母版页。他们有一个他们已经继承的基本类型。他们只是引用一个母版页并在其中呈现。
-
那么我如何引用同一页面以使用不同的母版页并出现这样的错误 --- 在母版页“MasterPage2.master”中找不到 ContentPlaceHolder 'ContentPlaceHolder1',验证内容控件的 ContentPlaceHolderID 属性内容页面。