?
Solved

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

Posted on 2011-02-15
8
Medium Priority
?
762 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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
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 2000 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…
Suggested Courses

764 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