Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...Declaring browser specific style sheets with VBDeclaring browser specific style sheets with VB
Previous
 
Next
New Post
9/14/2009 12:03 PM
 

I have a site that needs separate style sheets for internet explorer (mulitple versions) and opera browsers (firefox, chrome and safari all render correctly). I gather from my searches that I need to edit my Skin.ascx file and do something with CodeBehinds/CodeFiles, I'm just not sure exactly what! Can anyone help me, please? I've been frustrated by this for too long now!

 
New Post
9/14/2009 3:47 PM
 

There are 2 ways.

1. Add some VB to the skins code behind.

2. You can use Javascript

If you have no asp.net development experience I would go for the second option.

Example:

http://rafael.adm.br/css_browser_selector/

 
New Post
9/17/2009 4:32 AM
 

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.

 
New Post
9/17/2009 11:38 AM
Accepted Answer 

No, you should not edit that file..

Simpy add

<script runat="server">

Your Code

</script>

In your skins ascx file (on the  top below the register lines)

This method will not recognize FF on some linux versions correctly (at least not with ASP.NET 2.0, not sure about 3.5)

BTW,
If (Request.Browser.MajorVersion >= 7) Then

will inject the IE7 css also for IE8

 
New Post
9/17/2009 11:50 AM
 

Thanks a lot Timo. I found out the "<script runat="server">" method worked a few hours ago, but it's nice to have some clarification. Also, I know the implications of my use of >=, it's just unfinished code.

 

My new code if anyone is interested:


<script runat="server">
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        Dim oCSS As Control = Me.Page.FindControl("CSS")
        Dim cssFixFile As String = "None"
        Dim objLink As New HtmlLink()
       
        'detect browser
        If (Request.Browser.Browser.Equals("IE")) Then
            If (Request.Browser.MajorVersion >= 7) Then
                cssFixFile = "skin_IE7.css"
            ElseIf (Request.Browser.MajorVersion <= 6) Then
                cssFixFile = "skin_IE6.css"
            End If
        ElseIf (Request.Browser.Browser.Equals("Opera")) Then
            cssFixFile = "skin_Opera.css"
        End If
       
        If cssFixFile <> "None" Then
            'add stylesheets to the head section
            objLink.Attributes("rel") = "stylesheet"
            objLink.Attributes("type") = "text/css"
            objLink.Attributes("href") = SkinPath & cssFixFile
            If Not oCSS Is Nothing Then
                oCSS.Controls.AddAt(3, objLink)
            End If
        End If
    End Sub
</script>
 

 

I now have a new problem with my IE stylesheets that I've created a topic for, though. It's a weird one...

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...Declaring browser specific style sheets with VBDeclaring browser specific style sheets with VB


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out