I've been wondering how to programmatically change the background color for my whole website. I really wanted to continue to just use my css page. I've been thinking about it, but hadn't really worked on it today until a little while ago. This might be really obvious to some people, but I thought that I would share what I did. So here it goes.
I created a sytle sheet called "css.css." Here's what it looks like...
Then I created a webform called "css.aspx" and ripped out all of the code except for the page directive. Here's what that looks like...
Then in the page load of css.aspx I added the following code...
Then I created a regular webform and placed the reference to css.aspx in the <head> of the page, like so...
And that's it. Now I can change my variables in my css page. Just thought I would share that with everyone. If anyone has any better ideas then I'm definitely open to them.
L8r.
J
I created a sytle sheet called "css.css." Here's what it looks like...
Code:
body
{
background-color:@BackgroundColor;
color:@Font;
}
Then I created a webform called "css.aspx" and ripped out all of the code except for the page directive. Here's what that looks like...
Code:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="css.aspx.vb" Inherits="MyWebApp.css"%>
Then in the page load of css.aspx I added the following code...
Code:
'Open a file for reading
Dim FILENAME As String = Server.MapPath("css.css")
'Get a StreamReader class that can be used to read the file
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(FILENAME)
'Now, read the entire file into a string
Dim contents As String = objStreamReader.ReadToEnd()
'replacing my css "variables"
contents = Replace(contents, "@BackGroundColor", "Black")
contents = Replace(contents, "@Font", "White")
'write the contents (which will really just be my css file!
Response.Write(contents)
objStreamReader.Close()
Then I created a regular webform and placed the reference to css.aspx in the <head> of the page, like so...
Code:
<link href="css.aspx" rel="stylesheet" type="text/css">
And that's it. Now I can change my variables in my css page. Just thought I would share that with everyone. If anyone has any better ideas then I'm definitely open to them.
L8r.
J