Back to Top
The nuts and bolts for
Creative web development

Stylesheet changer with ASP and no JavaScript

This tutorial shows you how to create a StyleSheet changer using ASP, and a Cookie, without the need of Javascript.

The benefit of this is that if a user disables Javascript this script will still work, and should they have disabled cookies, then the default stylesheet will be used.

In the page to link to style sheets, place this in head


<% If Request.Cookies("StyleName") <> "" Then %>

<link href="stylesheets/<%=Request.Cookies("StyleName")%>" rel="stylesheet" type="text/css" />

<% Else %>

<link href="stylesheets/styles.css" rel="stylesheet" type="text/css" />

<% End If %>


'you need to change the folder path to point to where you store your style sheets.



in separate asp file, place



If Request.QueryString("TextSize") = "Standard" Then



ElseIf Request.QueryString("TextSize") = "Large" Then



End If



Response.Redirect + Request.QueryString("ReDirectURL")



'you need to change the style sheet names to reflect your own.

' save this page and call is process.asp



use the following text in a page to set cookie stylesheet


    <p align="center" class="text"><a href="process.asp?TextSize=Standard&ReDirectURL=<%=Request.ServerVariables("URL")%>">Standard Text &gt;&gt;</a> / <a href="process.asp?TextSize=Large&ReDirectURL=<%=Request.ServerVariables("URL")%>">Large Text &gt;&gt; </a></p>


You can add to the number of stylesheets you use, simply by adding ElseIF 's to the process.asp page.

Of course to make it 100% dynamic you can pass the style sheet name in the url when passing to the process.asp page, and then not require the ElseIf’s

Carl Grint

Carl Grint" Since graduating from university, I have worked with Charities and the Public sector, with my longest time being 3 years with the NHS until returning to freelance in 2003.

I would like to think my diverse experience of working for both the Public and Private sector gives me a good all rounding which enables me to approach projects with a unique perspective and enables me to bring new thoughts and initiatives to my work.

I have always enjoyed passing on the lessons I have learned so other developers can bypass the 'working out' time I had to go through, and writing my first two articles for DMXzone has given me a chance to pass on what I think are some good ways to improve on the standard Authentication behaviours Macromedia supply with Dreamweaver."

See All Postings From Carl Grint >>

Share this Article