how to sniff browser (VB )

Hi, I'm trying to serve a .css page to a website ONLY when the browser is IE8 or earlier.

In an html page it would be written as:
<!--[if (lt IE 9)&(!IEMobile)]>
<link rel="stylesheet" href="/IE8.css" media="all">

On my .ascx page I wrote:

<!--[if (lt IE 9)&(!IEMobile)]>
<dnn:DnnCssInclude ID="DnnCssIncludeIE8" runat="server" FilePath="/IE8.css" PathNameAlias="SkinPath" />

But the conditional doesn't work in this context (all browsers read the .css file)

So, I need to find out how to write the conditional browser sniffing statement ([if (lt IE 9)&(!IEMobile)]) in VB, on my .ascx page.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
According to this page , your syntax is correct except that I can't find any listing for 'IEMobile' in any of the pages about IE conditional comments.  Does it work if you just use <!--[if lt IE 9]> ?
Naitik GamitSoftware DeveloperCommented:
Look at this good article about : How To Create an IE-Only Stylesheet
In this article clearly defune the different syntax and conditions of CSS.
tommelkonianAuthor Commented:
Thanks for your responses.
Dave, I tried removing the '&(!IEMobile)' part, but got the same result.
To be clear, what's happening here, is the conditional is not working, so all browsers/versions are applying the IE8.css stylesheet. (I need all to ignore it except IE8 and earlier)
Naitik, thanks for the link.

My problem has to do with how to write the conditional browser/version testing code on my VB .ascx page (This is inside a DNN content management). (Not a straight .html page)

Thanks again
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Dave BaldwinFixer of ProblemsCommented:
You need to 'View Source' on the page in the browser to see what that is translated to.  Your HTML version above should work fine.  Anything that includes 'runat="server" ' get translated by the ASP.NET interpreter so you have to 'View Source' in the browser to see what it actually sends to the browsers.
tommelkonianAuthor Commented:
Thanks Dave. i just checked the browser's view source.

When using the first method (mentioned in my initial post), the source looks just like what I wrote on the page:

<!--[if (lt IE 9)&(!IEMobile)]>
<link rel="stylesheet" href="/IE8.css" media="all">

but doesn't apply the stylesheet in any browser/version.

When I use the second method mentioned, it does look different in the browser source:

<!--[if (lt IE 9)&(!IEMobile)]>

and applies the stylesheet in all browsers (disregarding the conditional) .

(The source looks the same in all browsers)

I tried both methods with a more simple if statement (just <!--[if (lt IE 9]>, or <!--[if IE]> ) with the same results.

Seems like I need to know how to write the conditional ("If ie 8 or earlier") on the .ascx page (VB)


Dave BaldwinFixer of ProblemsCommented:
I don't see how this does anything since it is not a valid link to a CSS file.

Open in new window

That does not make any sense.
tommelkonianAuthor Commented:
I think I figured it out!

DNN has a Skin object so in this context,

<dnn:STYLES runat="server" ID="StylesIE7" Name="IE7Minus" StyleSheet="/IE8.css" Condition="LT IE 9" UseSkinPath="true"/>

can work...
Looks good so far.
Dave BaldwinFixer of ProblemsCommented:
You still have runat="server" in that statement so you will have to 'View Source' in the browser to see what it actually generates.
tommelkonianAuthor Commented:
This is what is generated in the <head> in the browser source:

<!--[if LT IE 9]><link id="IE7Minus" rel="stylesheet" type="text/css" href="/Portals/_default/Skins/GoodDNN-LightBlue//IE8.css" /><![endif]-->
Dave BaldwinFixer of ProblemsCommented:
That looks ok.  What browsers and version are you using?  You know IE10 and above don't recognize IE conditionals.

I put that in one of my pages.  It is not recognized by Firefox but it is recognized by IE8.  If it is not working properly in your page then you need to go back to the 'View Source' to see what is screwing it up.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tommelkonianAuthor Commented:
It's working for me. Mozilla, Firefox and IE11 don't see the IE8.css stylesheet , as intended, and IE8 does see it. So it's working as I want.

Regarding IE10 and above not seeing IE conditionals, I think it's OK in this case as IE11's behavior is the same as Mozilla and Firefox. It's only IE8 and earlier that I want to apply the stylesheet to.


Martin LissOlder than dirtCommented:
I've requested that this question be closed as follows:

Accepted answer: 250 points for Dave Baldwin's comment #a40801746
Assisted answer: 250 points for Naitik Gamit's comment #a40801787

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.