我有一個最初從MastePage.master繼承的頁面。我想在我的項目的其他地方使用相同的頁面,但使用不同的主頁(MasterPage2.master)。爲此,我使用下面的代碼。動態更改asp內容標籤的MasterPage和ContentPlaceHolderID?
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設置爲ContentPlaceHolder2這是從MasterPage2.master。最初它是ContentPlaceHolder1。
但我在con =(內容)this.FindControl(「Content1」);
感謝
順便提一下,頁面不會從主頁面「繼承」。他們有一個基本類型,他們已經從中繼承。他們只需引用母版頁並在其中進行渲染。 – 2012-02-06 16:50:32
那麼如何引用相同的頁面以使用不同的母版頁來獲取像這樣的錯誤---在母版頁「MasterPage2」中找不到ContentPlaceHolder'ContentPlaceHolder1'。master「,請在內容頁面中驗證內容控件的ContentPlaceHolderID屬性。 – Tiger 2012-02-06 16:56:12