我試圖在任何地方找到此解決方案,但無法使其工作。隱藏面板在子頁面MasterPage ContentPlaceHolder在子頁面內容頁面
我有以下代碼。
MasterPage.master:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="My_MasterPage" %>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>
ChildMasterPage.master:
<%@ Master Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ChildMasterPage.master.cs" Inherits="My_ChildMasterPage" %>
<%@ Register TagPrefix="uc1" TagName="FileDirectoryOrganizer" Src="~/Controls/my.ascx" %>
<asp:Content ID="Content7" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:panel id="SideNav" runat="server">
<aside id="sideBar">
There are 2 User Controls <asp:uc1> inside of this area
</aside>
</asp:panel>
<div>
<asp:ContentPlaceHolder ID="contentBody" runat="server" />
<hr />
<h3>Related Topics</h3>
</div>
</asp:Content>
my.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/SubDirectory/ChildMasterPage.master" AutoEventWireup="true" CodeFile="my.aspx.cs" Inherits="SubDirectory_my" %>
<%@ MasterType VirtualPath="~/SubDirectory/ChildMasterPage.master" %>
<%@ Reference VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="contentBody" Runat="Server">
</asp:Content>
我試過在my.aspx以下代碼背後從ChildMasterPage.master隱藏「SideNav」面板:
1)
protected void Page_Load(object sender, EventArgs e)
{
ContentPlaceHolder cpHolder = this.Master.FindControl("Content7") as ContentPlaceHolder;
Panel p = cpHolder.FindControl("SideNav") as Panel;
p.Visible = false;
}
2)
protected void Page_Load(object sender, EventArgs e)
{
ContentPlaceHolder cpHolder = this.Master.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
Panel p = cpHolder.FindControl("SideNav") as Panel;
p.Visible = false;
}
3)
protected void Page_Load(object sender, EventArgs e)
{
Panel p = this.Master.FindControl("SideNav") as Panel;
p.Visible = false;
}
試圖加載使用的ChildMasterPage aspx頁面時,所有的這些給我下面的錯誤:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
最終,我想讓它不顯示任何樣式,以便在aspx頁面上不使用空格。像這樣的東西,它給了我與上面相同的錯誤:
protected void Page_Load(object sender, EventArgs e)
{
((Panel)this.Page.Master.FindControl("SideNav")).Style.Add("display", "none");
}
在此先感謝您提供的任何幫助。另外,如果這個問題已經在這裏得到解答,我提前表示歉意,但我無法找到它。至少沒有什麼工作。我仍然不太擅長C#,但我到了那裏。
感謝
馬克
如果我可以隱藏整個Content7 Content區域,那也可以。實際上可能更好。 –