Link to home
Start Free TrialLog in
Avatar of tommelkonian
tommelkonian

asked on

how to sniff browser ASP.net (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">
<![endif]-->

On my .ascx page I wrote:

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

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.

Thanks!

Tom
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

According to this page https://msdn.microsoft.com/en-us/library/ms537512%28v=vs.85%29.aspx , 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]> ?
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.

https://css-tricks.com/how-to-create-an-ie-only-stylesheet/
Avatar of tommelkonian
tommelkonian

ASKER

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
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.
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">
<![endif]-->

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)]>
<!--CDF(Css|/Portals/_default/Skins/GoodDNN-LightBlue//IE8.css?cdv=50)-->
<![endif]-->

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)

Thanks

Tom
I don't see how this does anything since it is not a valid link to a CSS file.
<!--CDF(Css|/Portals/_default/Skins/GoodDNN-LightBlue//IE8.css?cdv=50)-->

Open in new window

That does not make any sense.
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.
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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]-->
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

Thanks

Tom
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.