Welcome to Idea R | Branding - Web Agency - Digital Strategies
Switch to the mobile layout

      Idea R - Do others know who you are? Design your corporate identity
  • HomeHome
  • About UsAbout Us
  • ContactsContacts

Blog

Take a software geek from the 80s, add a new generation graphic designer and dilute with a long time marketing strategist. Shake vigorously and you'll get the Idea R's blog.

Change language... italiano

You may be interested in

How to fix your ASP.NET site to be responsive on Windows Phone

How to fix your ASP.NET site to be responsive on Windows Phone

Internet Explorer 10 for Windows Phone 8 suffers a bug when displaying responsive web sites. See how to fix it server-side with few lines of code.

Style sheets caching problems

Microsoft IIS caches all the style sheets that are placed inside the ASP.NET App_Themes folder, but there's a big problem...

Last published

Case study: branding and marketing for a magician

Case study: branding and marketing for a magician

Singular case study in the world of illusionism. See how we have created a brand and a web marketing campaign with exceptional results.

Can engineering industry sponsor art without going off topic?

How to design a page in an exhibition catalog of Biennale in Venice, for a customer who apparently has nothing to do with art.

Most popular

Lazy loading and the SEO problem, solved!

Lazy loading and the SEO problem, solved!

The best SEO solution to index your dynamically loaded contents, no more compromises!

Case study: TAV Engineering, branding for B2B services

How to create a brand that keeps distance from the cold and aseptic image of the metal industry, focusing instead on the human aspect.

Editor's pick

Mental marketing secret #1: the fake compromise

Mental marketing secret #1: the fake compromise

Can mentalism influence marketing? As a marketing professional and a long term magician, I will reveal you some tricks.

How to dramatically increase social media LIKEs to your web site

Here's a free download that I created some time ago. It's a good tool for increasing engagement, but use with caution.
newsletter

Stay informed on digital strategies

RSS feed

How to include CSS files programmatically in ASP.NET

Published on 7/31/2012
Categories: Web & Apps
How to include CSS files programmatically in ASP.NET

ASP.NET gives you the opportunity to add script blocks and JavaScript includes at runtime using methods like ClientScriptManager.RegisterClientScriptInclude().

How to perform a similar action to include style sheets?

There's no native method, but it's quite simple to perform: we're going to use the HtmlLink control.

HtmlLink link = new HtmlLink();
link.Href = "./MyFolder/MyStyleSheet.css";
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
Page.Header.Controls.Add(link);

An interesting parameter of the ClientScriptManager.RegisterClientScriptInclude() method is the Key, that's used to assure you do not add the same include twice.

How to perform the same thing with the previous code?
The solution is to give the control a unique id:

public void AddStyleLink(String Key, String StyleUrl)
{
    if (!String.IsNullOrEmpty(Key))
        if (Page.Header.FindControl(Key) != null) return;
 
    HtmlLink link = new HtmlLink();
    if (!String.IsNullOrEmpty(Key)) link.ID = Key;
    link.Href = StyleUrl;
    link.Attributes.Add("type", "text/css");
    link.Attributes.Add("rel", "stylesheet");
    Page.Header.Controls.Add(link);
}

 

Did you find this article useful?

If you think your friends will like it too, share it on Facebook.
You have only to press the button here below!

 

You are the reader number 5,587.

Comments

comments powered by Disqus
Creative Commons License

Photographies, videos, graphics and texts by Idea R are licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Previous article

Previous article

Google Tag Manager: stop sinking into scripts

Next article

Internal campaigns with Google Analytics and .NET AdRotator

Next article
  • Visual Communication, Art DirectionVisual Communication, Art Direction
  • Apps, Cloud, Mobile, Software DesignApps, Cloud, Mobile, Software Design
  • Digital StrategiesDigital Strategies
  • BlogBlog
Touching finger
RSS feed
Blog

Scroll to top