Notes, Tricks and Tips on ASP.NET Coding
Earlier I discussed how to dynamically link to background images in ASP.NET. This is a little different, and repuires a little different techniqe. 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:
<link rel="stylesheet" id="Stylesheet1" type="text/css" runat="server" />
The key is the 'id'
Now put this code in the 'on load' event:
Stylesheet1.Attributes("href") = ResolveUrl("~\styles\StyleSheet.css")
That'll fix the problem.
About Steve Gray
Steve is a seasoned (translate: old) developer in VB and ASP.NET. He spends most of his time in Dynamics GP, writing custom mods for consulting firms. Crystal reports, eConnect, VS Tools for Dynamics... anything that comes along.