[thelist] (OT) Stylesheet based on URL
Joshua Olson
joshua at waetech.com
Thu Nov 6 07:41:25 CST 2003
----- Original Message -----
From: "Les Lytollis" <leslytollis at dimensions-corporatewear.co.uk>
Sent: Thursday, November 06, 2003 8:09 AM
> Yeah, nice solution - thanks Ken - I obviously need to look at the .NET
> stuff a bit more...
Les,
As with many other languages there is usually more than one way to
accomplish the same result. While Ken's solution is correct, I'd also like
to bring to the table an alternative:
Add a LINK to the HEAD and then add the runat to the LINK. In this way the
LINK tag itself acts as the placeholder for the stylesheet.
Here's why...
If a new developer was to come look at the page source it would not be
obvious to them how the link tag was generated if the tag was dynamically
inserted using the method offered by Ken. By actually placing the LINK tag
into the HEAD tag to serve as a placeholder you give the person a starting
point (the id of the tag) if they need to debug.
One gotcha is "what if they don't want a style sheet for a particular page?"
I'd speculate that instances where the style sheet will not be defined will
be the exception, not the rule. In those cases you could set the tag's
visibility to false and the tag would disappear from the rendered page.
Here's an example based on Ken's code:
<script runat="server">
Sub Page_Load(sender as object, e as eventargs)
SetStyles()
End Sub
Sub SetStyles()
Dim strServerName as String
Dim strStyleSheetName as String
strServerName =
Request.ServerVariables("Server_Name").toString.ToLower()
Select Case strServerName
Case "company1.mydomain.co.uk"
strStyleSheetName = "company1.css"
Case "company2.mydomain.co.uk"
strStyleSheetName = "company2.css"
Case "company3.mydomain.co.uk"
linkStylesheet.Visible = False
Case Else
strStyleSheetName = "default.css"
End Select
linkStylesheet.Attributes("href") = "/inc/CSS/" & strStyleSheetName
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server" id="theHead">
<title>Some Sample Page</title>
<link id="linkStylesheet" runat="server" rel="stylesheet"
type="text/css"></link>
</head>
<body>
</body>
</html>
<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com
706.210.0168
More information about the thelist
mailing list