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);
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.
0
Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.
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.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Browser.Browser == "IE")
{
System.Web.UI.HtmlControls
link.Attributes.Add("media
link.Href = "Css/" + value + ".css";
link.Attributes.Add("type"
link.Attributes.Add("rel",
Page.Header.Controls.Add(l
}
}
}