Link to home
Start Free TrialLog in
Avatar of bcolladay
bcolladayFlag for United States of America

asked on

How to put a conditional-dynamic stylesheet in header ASP.net C#

I want to add this to my masterpage:

<!--[if IE]>
<link rel="stylesheet" href="css/clinicblue7.css" media="screen" type="text/css" />
<![endif]-->
<!-- tell iPhone not to shrink mobile website -->

But I want the set the "clinicblue7.css" part in the c# code.  I am currently adding other stylesheets dynamically using this method. How do I do a similar thing with the above referenced code.


System.Web.UI.HtmlControls.HtmlLink link = new HtmlLink();
        link.Attributes.Add("media", "screen and (min-device-width: 481px)");
        link.Href = "Css/" + value + ".css";
        link.Attributes.Add("type", "text/css");
        link.Attributes.Add("rel", "stylesheet");
        Page.Header.Controls.Add(link);

Open in new window

Avatar of gdupadhyay
gdupadhyay
Flag of United States of America image

Please see this URL:
http://www.aspnettutorials.com/tutorials/themes/usingcss-csharp.aspx

let me know if you are looking different.
Avatar of bcolladay

ASKER

Thanks, but I am just looking to use the code I referenced to see that the browser is Internet Explorer and to use a specified stylesheet that I will specify dynamically in the code behind.  This will have no end user interaction.
You can't determine the client browser by using c# or vb.net.
You have to use client side scripts only.
ASKER CERTIFIED SOLUTION
Avatar of gdupadhyay
gdupadhyay
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
Yeah, I don't want to use c# to determine the browser.  I just want to dynamically specify what style sheet to use if that browser condition is met in the head section of html.  

this:
<!--[if IE]>
<link rel="stylesheet" href="css/clinicblue7.css" media="screen" type="text/css" />
<![endif]-->
<!-- tell iPhone not to shrink mobile website -->

is what I will be using but I need to change the name of the css based on other things happening.
"other things happening"... like?
Thank you very much!