bcolladay
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.
<!--[if IE]>
<link rel="stylesheet" href="css/clinicblue7.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);
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.
i found one more good artical for dynamic CSS:
http://www.eggheadcafe.com/tutorials/aspnet/8cc10b36-1ea6-4401-af34-710717edcc94/dynamically-link-stylesheet-to-aspnet-page.aspx
http://www.eggheadcafe.com/tutorials/aspnet/8cc10b36-1ea6-4401-af34-710717edcc94/dynamically-link-stylesheet-to-aspnet-page.aspx
You can't determine the client browser by using c# or vb.net.
You have to use client side scripts only.
You have to use client side scripts only.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
this:
<!--[if IE]>
<link rel="stylesheet" href="css/clinicblue7.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?
ASKER
Thank you very much!
http://www.aspnettutorials.com/tutorials/themes/usingcss-csharp.aspx
let me know if you are looking different.