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

徘徊边缘 提交于 2019-12-02 00:52:46

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;
}

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)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!