Dynamic content switching based on stylesheet
I'm making a new design for my website, but I want to keep the old one and possibly switch between the two.
Unfortunat开发者_StackOverflow社区ely, I've changed the content on the Master Page (luckily I have a backup). What I was thinking was to keep separate master files for each theme, and then just determine which one to server based on which stylesheet is loaded.
The only way I can think to do this is to keep a "settings" file on the website that has a "stylesheet=1/2/3/4/etc"
line. Depending on the number there, the server will serve the correct master page.
Alternatively it might be easier to do something similar, but instead of serving a whole different master page, set a specific stylesheet to use.
In both cases, I need a little help with actually doing the work on the server. I can read a text file (even encrypt/decrypt a file before and after it gets read for security), but actually giving the server the instructions based on what is read is where I'm lost.
Any suggestions will be greatly appreciated.
How are you deciding which style should be loaded?
The master page should dictate which stylesheet is loaded not the other way around.
How are you allowing the users to switch the style? I would pass it as a querystring parameter to the first page that is called and then add it to the Session. Once you have done that, in the Page_PreInit event of all the pages have the following code;
void Page_PreInit(Object sender, EventArgs e)
{
if(Session["masterpage"] != null)
{
this.MasterPageFile = (String) Session["masterpage"];
}
}
This way, each MasterPage would have its own style sheet.
You can also store the masterpage name into a cookie. This will allow the user to keep on using the style they have selected event after the session has expired.
精彩评论