Results 1 to 5 of 5

Thread: [RESOLVED] Changing CSS on Browser Type?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    261

    [RESOLVED] Changing CSS on Browser Type?

    In my site, I want to have 3 differet CSS's. When a user goes to the site I want the CSS to be selected programatically based on the browser type the user has.

    I check for the browser type in Global.asax and set a flag. But how/where do I programmatically change the CSS based on my flag being true
    Last edited by seidel1; Aug 28th, 2006 at 02:20 PM. Reason: RESOLVED

  2. #2
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Re: Changing CSS on Browser Type?

    Create the css classes separately, then for the controls you want to change it:

    MyControl.Attributes.Add("cssclass", "IEcss1")

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    261

    Re: Changing CSS on Browser Type?

    I don't want to put logic in for each control, that could be a lot of work, Since I am checking on startup for the browser type, can't I just specify the different CSS Class for the entire page?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    261

    Re: Changing CSS on Browser Type?

    I figured it out:

    In Global ASAX,
    VB Code:
    1. Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    2.        
    3.         Session("Theme") = "FFTheme"
    4.         BrowserCheck()
    5. End Sub
    6.  
    7.     Public Sub BrowserCheck()
    8.         'Detect Client Browser Environment
    9.         Dim strUserAgent ' browser type capture
    10.  
    11.         strUserAgent = UCase(CStr(Request.ServerVariables("HTTP_USER_AGENT")))
    12.  
    13.         'Explorer
    14.         If InStr(strUserAgent, "MSIE 5") Then
    15.             Session("Theme") = "IETheme"
    16.         ElseIf InStr(strUserAgent, "MSIE 6") Then
    17.             Session("Theme") = "IETheme"
    18.         ElseIf InStr(strUserAgent, "MSIE 7") Then
    19.             Session("Theme") = "IETheme"
    20.         End If
    21.  
    22.     End Sub

    Than on the page I handle it in pre-init

    VB Code:
    1. Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As _
    2.     System.EventArgs) Handles Me.PreInit
    3.         Page.Theme = Session("Theme")
    4.     End Sub

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] Changing CSS on Browser Type?

    You may also want to implement browsercaps, so that ASP.NET renders HTML 4 instead of 3.2 for firefox.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width