Solved

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

Posted on 2011-02-15
8
754 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

740 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