Yes, today is my birthday. How old am I? Well, my 5 year old says I must be at least 28! He’s a good lad – I’ll keep him.
Funnily enough, my wife has been sick this week so I’ve been working from home until yesterday, and tomorrow I’m taking a day off for other reasons. So my birthday present is to spend a day at work!! Not sure how to take that, really…
Categories: Miscellaneous
Recently, while working on a new ASP.NET MVC website for Glenmore Park Anglican Church, I have found myself wishing for the same server-side text substitution in CSS files that we enjoy in ASPX files (the <%= … %> construct).
It seems that this is much easier to accomplish that it may appear at first.
Create an ASP.NET page (say, site.aspx), and below the Page specification, include your CSS tags.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="site.aspx.cs" Inherits="Content.CSS.site" %>
body {
margin: 0px;
font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, Sans-Serif;
background-color: #666666;
background-image: url(<%= AppHelper.ImageUrl("MyImage.png") %>);
}
Now comes the tricky bit. In the code-behind file, include the following:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/css";
}
Now just use site.aspx rather than site.css in your CSS links, and voila!
Categories: Coding
Tagged: ASP.NET, CSS