Rusty S. Swayne

tidbits and tangents

Rusty S. Swayne

My name is Russell S. Swayne although I have gone by Rusty all of my life. I own a small web design/development studio named Mindfly (http://www.mindfly.com), have a wonderful wife and very precocious and yet extremely charming daughter.

contact me Feed
 

Correct the stylesheet link tag for ASP.NET 2.0 Themes

Even though this method is documented fairly well (and to be honest I don't remember where I got this code snippet) I often have people argue that they don't use asp.net themes as they break when rewritting urls.  The problem stems from the fact that when the them renders by default the link tag created uses a relative path such as:

<link rel="stylesheet" type="text/css" href="App_Themes/rustyswayne/a_normalize.css" />

and what you really need if for it to read:

<link rel="stylesheet" type="text/css" href="/App_Themes/rustyswayne/a_normalize.css" />

You can get around this problem by Overriding the Render routine in your page. I usually do this in a BasePage class my pages inherit from:

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim ctl As Control
For Each ctl In Page.Header.Controls
If TypeOf (ctl) Is HtmlLink Then
Dim linkTag As HtmlLink = CType(ctl, HtmlLink)
If (linkTag IsNot Nothing) And linkTag.Href.StartsWith("~/") Then
If Request.ApplicationPath = "/" Then
linkTag.Href = linkTag.Href.Substring(1)
Else
linkTag.Href = Request.ApplicationPath & "/" & linkTag.Href.Substring("~/".Length)
End If
End If
End If
Next
End Sub

Add comment


(Will show your Gravatar icon)  





Live preview

said...

-July 6. 2008 08:54

 
 

Powered by BlogEngine.NET 1.2.0.0. Original Design by Heather Alvis.
Sign in