How to hide content on certain pages and not others via a Master Page?

后端 未结 2 1635
终归单人心
终归单人心 2021-01-23 09:27

Read this thread but didn\'t really answer my question and there were quite a few suggestions so not sure if they are on the right track: Master Page content filtering with res

2条回答
  •  抹茶落季
    2021-01-23 09:53

    Expose a property on the MasterPage to allow content pages to override default behavior if needed.

    In the MasterPage:

    private bool showFooter = true;
    
    public bool ShowFooter { get {return showFooter;} set {showFooter = value;} }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        footerControl.Visible = showFooter;
    }
    

    Make sure content pages that need to access the property have the following line in the aspx:

    <%@ MasterType TypeName="XXX" %>
    

    and in the content pages code-behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        Master.ShowFooter = false;
    }
    

提交回复
热议问题