Last post Jan 22, 2008 05:51 AM by ovaisgeo
Jan 12, 2008 06:59 AM|ops_pete|LINK
Made a theme that for one reason or another works fine on the modern browsers, ie7, ff etc but not on ie6. I have made a theme that alters the CSS enough that it all works fine with ie6 (but is a complete mess in everything else), now but I need a way to
make it switch the themes should it detect the ie6 browser.
I'm not sure if this is possible or how I would do it. the only backup plan I have come up with is to take the CSS files out of the theme and use the old trick of conditional comments but it's not a very tidy solution.
Any help appreciated.
Jan 12, 2008 10:19 AM|MorningZ|LINK
Its definitely possible.... what you need to do is hook into the Page object's "PreInit" event and
read the UserAgent string and set Me.Theme (or this.Theme if in C#) accordingly
Jan 12, 2008 11:52 AM|ops_pete|LINK
Thanks for the reply! It got me half way to where I want to be, didn't realise it would be so simple to do but I am glad it was!
From that link you sent me I came up with this script:
protected void Page_PreInit(object sender, EventArgs e)
if (Request.Browser.Type == "IE6")
Page.Theme = "Standard-ie6";
Page.Theme = "Standard";
Pretty self explanatory, if the browser type is equal to IE6 (use the link in the 4guysfromrolla link to find out what the return value is for different browsers). then it runs my ie theme if anything else (because the other theme works fine with all the
other browsers) then it runs the normal one.
At the moment I have had to copy n paste this into all the code-behinds of my pages which isn't the best scenario but it works which for the immediate future is fine. IT would seem that masterpages get processed after the PreInit so you can't set the theme
in the masterpages... real pain!
Any good work arounds for this would be very welcome!
Jan 12, 2008 01:37 PM|MorningZ|LINK
I'll point you to another 4guys article, this one:
What you want to do so you don't have to copy and paste that code across all pages is put that in one single class, and then have your pages inherit from your class, not the System.Web.UI.Page class, then the code is wired in automatically
Jan 20, 2008 07:15 AM|ops_pete|LINK
Thanks again, I'd just literally done that before reading your post! Works a treat
Jan 22, 2008 05:51 AM|ovaisgeo|LINK