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

后端 未结 2 1634
终归单人心
终归单人心 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:46

    In your MasterPage:

    protected void Page_Load(object sender, EventArgs e)
    {
       var page = HttpContext.Current.Handler as Page;
       FooterControl.Visible = HttpRequest.IsAuthenticated && !(page is LoginPage)
    }
    
    • HttpContext.Handler Property
    • is (C# Reference)
    0 讨论(0)
  • 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;
    }
    
    0 讨论(0)
提交回复
热议问题