I know I can use Javascript, but I'd like to use the code behind option. The problem I'm having is declaring the code behind in my Skin.ascx file. As such I'm not sure whether the code I added to the AddStyleSheet() sub in the code behind works. Just to verify, the file at /admin/Skins/Styles.ascx.vb is the code behind file, correct?
Here is the Add Stylesheet sub from my code behind:
Protected Sub AddStyleSheet()
'Find the placeholder control
Dim objCSS As Control = Page.FindControl("CSS")
If Not objCSS Is Nothing Then
'First see if we have already added the <LINK> control
Dim objCtrl As Control = Page.Header.FindControl(id)
If objCtrl Is Nothing Then
Dim skinpath As String = String.Empty
If UseSkinPath Then
skinpath = CType(Me.Parent, Skin).SkinPath
End If
Dim cssFixFile As String = String.Empty
Dim objLink As New HtmlLink()
If (Request.Browser.Equals("IE")) Then
If (Request.Browser.MajorVersion >= 7) Then
'IE7 detected - create a full path to the skin_IE7.css file
cssFixFile = Path.Combine(skinpath, "skin_IE7.css")
ElseIf (Request.Browser.MajorVersion = 6) Then
'IE6 detected - create a full path to the skin_IE6.css file
cssFixFile = Path.Combine(skinpath, "skin_IE6.css")
End If
End If
objLink.ID = CreateValidID(Name)
objLink.Attributes("rel") = "stylesheet"
objLink.Attributes("type") = "text/css"
'Load in the CSS file for the browser
If (cssFixFile = "") Then
'if a CSS file is needed, this part loads it in
objLink.Href = skinpath + StyleSheet
Else
objLink.Href = cssFixFile
End If
If IsFirst Then
'Find the first HtmlLink
Dim iLink As Integer
For iLink = 0 To objCSS.Controls.Count - 1
If TypeOf objCSS.Controls(iLink) Is HtmlLink Then
Exit For
End If
Next
AddLink(objCSS, iLink, objLink)
Else
AddLink(objCSS, -1, objLink)
End If
End If
End If
End Sub
Granted, I have little ASP.NET experience, but some pointers as to where I'm going wrong would be appreciated. Thanks.