Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 1st, 2006, 08:04 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 121
CSS Switcher/Stylesheet Chooser

Here is an example of a CSS Switcher in ASP.

http://computer-helpforum.com/asp/a...SS_Switcher.asp



Check to see if the user requested a new CSS file
asp Code:
Original - asp Code
  1.  
  2. 'Check to see if cssSelector was submitted
  3. If Request("cssSelector") <> "" Then
  4.  
  5.     'Save the cookie with the style selection
  6.     Response.Cookies("cssSelected") = Request("cssSelector")
  7.     Response.Cookies("cssSelected").Expires = DateAdd("y",1,Now)
  8.    
  9.     'Optional cookie attributes
  10.     'path_info  = Request.ServerVariables("PATH_INFO")
  11.     'divider = InStrRev(Request.ServerVariables("PATH_INFO"),"/")
  12.     'path = Left(path_info,divider)
  13.     'Response.Cookies("cssSelected").Domain = Request.ServerVariables("SERVER_NAME")
  14.     'Response.Cookies("cssSelected").Path = path
  15.    
  16.     'Redirect to refresh the page
  17.     Response.Redirect(Request.ServerVariables("SCRIPT_NAME"))
  18. End If


The CSS files can be loaded from the server
asp Code:
Original - asp Code
  1.  
  2. 'Get CSS files using FSO. If you want to load a list of .css files from the server then set getCSSFiles = True
  3.  
  4. getCSSFiles = False
  5.  
  6. If getCSSFiles Then
  7.  
  8. set fs=Server.CreateObject("Scripting.FileSystemObject")
  9. set fo=fs.GetFolder(Server.MapPath("."))
  10.     for each FileName in fo.files
  11.         If Right(FileName.Name,4) = ".css" Then
  12.             cName = FileName.Name
  13.             cTitle =  UCase(Left(FileName.Name,1)) & LCase(Mid(FileName.Name,2,Len(FileName.Name)-5))
  14.            
  15.             Redim Preserve cssArr(1,i)
  16.             cssArr(0,i) = cName
  17.             cssArr(1,i) = cTitle
  18.             i=i+1
  19.         End If
  20.     next
  21. set fo=nothing
  22. set fs=nothing


or hardcoded
asp Code:
Original - asp Code
  1.  
  2. Else
  3.     'Hardcoded CSS files. getCSSFiles = False
  4.     ReDim cssArr(1,2)
  5.     cssArr(0,0) = "red.css" 'Name of CSS file
  6.     cssArr(1,0) = "Red" 'Title/Description of CSS file
  7.    
  8.     cssArr(0,1) = "green.css"
  9.     cssArr(1,1) = "Green"
  10.    
  11.     cssArr(0,2) = "blue.css"
  12.     cssArr(1,2) = "Blue (serif)"
  13. End If



Grab the selected CSS from the cookie or set a default
asp Code:
Original - asp Code
  1.  
  2. 'See if a cookie is present
  3. If Request.Cookies("cssSelected") <> "" Then
  4.     'If it is then set the CSS variable to the cookie value.
  5.     css = Request.Cookies("cssSelected")
  6. Else
  7.     'Otherwise default it to something else. Here it is the first value in the array (red.css)
  8.     css = cssArr(0,0)
  9. End If


Set the CSS
Code:
<link href="<%=css%>" rel="stylesheet" type="text/css">




Output the CSS choices

Select/Dropdown
asp Code:
Original - asp Code
  1.  
  2. <form method="post" action="">
  3.     <select name="cssSelector">
  4.     <%For x=0 To Ubound(cssArr,2)%>
  5.         <option value="<%=cssArr(0,x)%>"<%If cssArr(0,x) = css Then%> selected<%End If%>><%=cssArr(1,x)%></option>
  6.     <%Next%>
  7.   </select>
  8.    <input name="setStyle" type="submit" id="setStyle" value="Set Style">
  9. </form> 


or Links
asp Code:
Original - asp Code
  1.  
  2. <%For x=0 To Ubound(cssArr,2)%>
  3.     <a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?cssSelector=<%=cssArr(0,x)%>"><%=cssArr(1,x)%></a><br>
  4. <%Next%>
Attached Files
File Type: zip CSS_Switcher.zip (3.2 KB, 257 views)
__________________
CyberTechHelp

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > CSS Switcher/Stylesheet Chooser


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT