Mar
10
Written by:
Steve Gray
3/10/2011 6:54 PM
Earlier I discussed how to dynamically link to background images in ASP.NET. This is a little different, and requires a little different technique. The issue is that when a master page serves a page in a subdirectory, it can't find the style sheet. Not a problem, really, except for the way that ASP.NET 2.0 development works. In development, the site runs as a virtual site, and the path to the CSS is different in development than when published.
This code will fix that.
Create the CSS links in the header section of the master page like this:
Code Snippet
- <link rel="stylesheet" id="blackicetheme" type="text/css" runat="server" />
The key is the 'id'
Now put this code in the 'on load' event:
Code Snippet
- blackicetheme.Attributes("href") = ResolveUrl("~/themes/20101/blackice/theme.css")
That'll fix the problem.
As always, I welcome your comments!