[thelist] (OT) Stylesheet based on URL

Ken Schaefer ken at adOpenStatic.com
Thu Nov 6 05:44:13 CST 2003


There lots of ways - you could create your own class that inherits from
Page, and exposes a property that you set (for example), but assuming you're
just writing an .aspx page. One of the benefits of ASP.Net is that you don't
need the ugly inline spaghetti mess that characterised ASP (and a lot of
other interpreted languages of the same vintage).

A simple example would be below. Notice how the bit between <html></html>
contains no ASP.Net code? That makes it easier to sort out presentation
issues in the HTML editor of your choice (you can just cut-n-paste it for a
real quick-n-nasty approach to generating the HTML)

<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"
            Case "company2.mydomain.co.uk"
                strStyleSheetName = "company2"
            Case Else
                strStyleSheetName = "default"
        End Select

        theHead.Controls.Add(New LiteralControl("<link rel=""stylesheet""
type=""text/css"" 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>
    </head>

    <body>
    </body>
</html>

----- Original Message ----- 
From: "John Dobson" <j.dobson at find-a-part.com>
To: <thelist at lists.evolt.org>
Sent: Thursday, November 06, 2003 10:05 PM
Subject: RE: [thelist] (OT) Stylesheet based on URL


> If this is ASP.Net you don't want to do it this way...
>
> Cheers
> Ken

How would it be better coded?

Me being green too...

John




More information about the thelist mailing list