Solved

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

Posted on 2011-02-15
8
757 Views
Last Modified: 2013-11-19
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

0
Comment
Question by:bcolladay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 9

Expert Comment

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

let me know if you are looking different.
0
 
LVL 4

Author Comment

by:bcolladay
ID: 34898976
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
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 34898990
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 9

Expert Comment

by:gdupadhyay
ID: 34899062
You can't determine the client browser by using c# or vb.net.
You have to use client side scripts only.
0
 
LVL 9

Accepted Solution

by:
gdupadhyay earned 500 total points
ID: 34899119
Use this concept (Please let me know how it is):

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Browser.Browser == "IE")
            {
                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);
            }
        }
    }
0
 
LVL 4

Author Comment

by:bcolladay
ID: 34899131
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.
0
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 34899170
"other things happening"... like?
0
 
LVL 4

Author Closing Comment

by:bcolladay
ID: 34899299
Thank you very much!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Print a <div></div> only 5 51
SP inserts data with order number, then push the rest one order up 11 39
asp.net repeater 2 31
Can Selenium do Load Testing? 2 56
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question