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

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

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

Method 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)
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x