views:

1301

answers:

6

I'm working on a website which will switch to a new style on a set date. The site's built in semantic HTML and CSS, so the change should just require a CSS reference change. I'm working with a designer who will need to be able to see how it's looking, as well as a client who will need to be able to review content updates in the current look as well as design progress on the new look.

I'm planning to use a magic querystring value and / or a javascript link in the footer which writes out a cookie to select the new CSS page. We're working in ASP.NET 3.5. Any recommendations?

I should mention that we're using IE Conditional Comments for IE8,7,and 6 support. I may create a function that does a replacement:

<link href="Style/<% GetCssRoot() %>.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 8]>
<link type="text/css" href="Style/<% GetCssRoot() %>-ie8.css" rel="stylesheet" />
<![endif]-->
<!--[if lte IE 7]>
<link type="text/css" href="Style/<% GetCssRoot() %>-ie7.css" rel="stylesheet" />
<![endif]-->
<!--[if lte IE 6]>
<link type="text/css" href="Style/<% GetCssRoot() %>-ie6.css" rel="stylesheet" />
<![endif]-->
+1  A: 

I would suggest storing the stylesheet selection in the session so you don't have to rely on the querystring key being present all the time. You can check the session in Page_Load and add the appropriate stylesheet reference. It sounds like this is a temporary/development situation, so go with whatever is easy and works.

if (!String.IsNullOrEmpty(Request.QueryString["css"]))
Session.Add("CSS",Request.QueryString["css"]);
palmsey
+8  A: 

In Asp.net 3.5, you should be able to set up the Link tag in the header as a server tag. Then in the codebehind you can set the href property for the link element, based on a cookie value, querystring, date, etc.

In your aspx file:

<head>
  <link id="linkStyles" rel="stylesheet" type="text/css" runat="server" />
</head>

And in the Code behind:

protected void Page_Load(object sender, EventArgs e) {
  string stylesheetAddress = // logic to determine stylesheet
  linkStyles.Href = stylesheetAddress;
}
Yaakov Ellis
Thanks, didn't think of this, but .NET wasn't playing nice with this:<link rel="stylesheet" href="/style.css<%= VersionQueryString %>" type="text/css" />
Aaron
Great idea, and by far the most "clean" solution suggested :)
Moulde
+3  A: 

You should look into ASP.NET themes, that's exactly what they're used for. They also allow you to skin controls, which means give them a set of default attributes.

Shawn Simon
A: 

I would do the following:

www.website.com/?stylesheet=new.css

Then in your ASP.NET code:

if (Request.Querystring["stylesheet"] != null) {
Response.Cookies["stylesheet"].Value = Request.QueryString["stylesheet"];
Response.Redirect(<Current Page>);
}

Then where you define your stylesheets:

if (Request.Cookies["stylesheet"] != null) {
// New Stylesheet
} else {
// Default
}
GateKiller
what do you do when the user navigates to another page? comes in from an outside link?
Jason
A: 

@modesty I like the concept of themes, but they don't work well with conditional comments: http://adam.kahtava.com/journal/2006/11/09/The+Problems+With+Themes+Skins.aspx

Jon Galloway
A: 

Take a look at http://conditional-css.com/ They have a ashx handler that can read the conditional directives and emit the css for that browser.

Jafin