[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
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")
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?
Re: Changing CSS on Browser Type?
I figured it out:
In Global ASAX,
VB Code:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session("Theme") = "FFTheme"
BrowserCheck()
End Sub
Public Sub BrowserCheck()
'Detect Client Browser Environment
Dim strUserAgent ' browser type capture
strUserAgent = UCase(CStr(Request.ServerVariables("HTTP_USER_AGENT")))
'Explorer
If InStr(strUserAgent, "MSIE 5") Then
Session("Theme") = "IETheme"
ElseIf InStr(strUserAgent, "MSIE 6") Then
Session("Theme") = "IETheme"
ElseIf InStr(strUserAgent, "MSIE 7") Then
Session("Theme") = "IETheme"
End If
End Sub
Than on the page I handle it in pre-init
VB Code:
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Me.PreInit
Page.Theme = Session("Theme")
End Sub
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.