views:

34

answers:

1

One of the features of a website I'm working on is that you can "maximize" the contents of the page, basically removing all the outer elements of the page, navigation, banners, etc.

This is currently done in what seems like the worst possible way:

<%
if (shouldBreakFrame)
{
%><!--#include file="header.include" --><%
}
%>

// Contents of page here

<%
if (shouldBreakFrame)
{
%><!--#include file="footer.include" --><%
}
%>

The footer is basically just closing tags from the header.

So I want to clean this up and am working on a master page but I'm not sure how to properly "remove" the html elements that wrap the contents when we want to maximize the page. It would be easy for tags that open/close on one side or the other of the content, but what about div/tables that open at the top and close at the bottom?

Edit: To clarify exactly what the output looks like and why I can't just "hide" the elements with javascript or .Visible property here is what the output might look like and what it should look like after the surrounding elements are hidden:

<table>
<tr>
    <td>Header</td>
</tr>
<tr>
    <td>
        Page content here
    </td>
</tr>
</table>

And after hiding stuff all that is left is Page content here.

So if I just hide the table, the content would disappear as well.

+2  A: 

You have a few options here, both require the elements to be already contained within the markup (unless you want to go down the ajax route).

The first would be using CSS to show/hide elements via the display:none attribute thats explained here. However I would have to say may favourite method would be to use jQuery. This contains two functions, show() and hide() but interestingly also includes a toggle() function which will show/hide elements depending on their current visibility. This should allow your code to be tidier and wouldn't have to worry about if(shouldBreakFrame). I found this interesting article on it which should get you started.

The only other option I can think of is either duplicate the code (in the same masterpage) or have two seperate masterpages. After all a masterpage is basically a template, and thats the part you want to change.

m.edmondson
I don't think this really solves my problem because if I "hide" the surrounding elements it would hide the entire _content_ of the page as well.
thelsdj
Ah I understand now. The only other option I can think of is either duplicate the code (in the same masterpage) or have two seperate masterpages. After all a masterpage is basically a template, and thats the part you want to change.
m.edmondson
Just had a brainwave. Instead of setting your contents within the elements you're wanting to show/hide you could have them floating on top. This would then allow you to use the above method. If you use CSS float you remove them from the normal flow of the page, so you could have the elements in a hidden table or somesuch that sit on top of the header/footer.
m.edmondson
Yeah I want to make as little change to the main page as possible so probably won't do CSS float but will try dual Master page (with a base-class that handles the switching). If you edit your answer to include suggestions from comment I'll mark as accepted
thelsdj
Glad to have helped! I've edited my answer now.
m.edmondson