问题
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 respect to asp page
What I have is a site with 1 Master Page and in it is a global footer that all pages use. I want to eliminate the footer on only 1 page (i.e. the login page) but keep all the other master page content intact.
I know I could create a separate Master Page just for this login page but it seems overkill. Is there a way to put in some logic that if it's only this specific page that it would hide the footer and then show on every other page?
Thanks for any tips/suggestions.
Edit: There was already a Page Load sub in the code behind. All I had to add was - MasterPage_Footer.Visible = False
on the If statement when users were not logged in and set it to True
when they were logged in. Works like a charm. Thanks for all the suggestions.
回答1:
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;
}
回答2:
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)
来源:https://stackoverflow.com/questions/10302545/how-to-hide-content-on-certain-pages-and-not-others-via-a-master-page