Try Now

CSS Include User Control

by Mustafa Kipergil
Publication date:
Nov 27, 2009, 10:09 AM


  • Sitefinity 3.7
  • Sitefinity 3.6

Price: $ 0
For some pages you need to include custom css styles which is only used in that page. When this is the case including this style to App_Themes folder is unnecessary. (It loads this in every page.)

So by this control you can easiliy include your custom css file simply by dragging it onto a page.
You only need to fill the css file path property like : ~/customCssFiles/banner.css

Sitefinity CMS validated extension

Example code:

using System;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Linq;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.HtmlControls;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Xml.Linq;  
using System.ComponentModel;  
public partial class CSSInclude : System.Web.UI.UserControl  
    [Bindable(true), Category("Settings"), Description("This is the url of the css file. Use (~) to reference the file. Ex : ~/css/stylesheet.css"), DefaultValue("")]  
    private string cssUrl;  
    public string CssUrl  
            return this.cssUrl;  
            this.cssUrl = value;  
    protected void Page_Load(object sender, EventArgs e)  
        if (this.Page != null && this.Page.Header != null)  
            string url = Page.ResolveUrl(CssUrl);  
            HtmlGenericControl cssLink = new HtmlGenericControl("link");  
            cssLink.Attributes["rel"] = "stylesheet";  
            cssLink.Attributes["type"] = "text/css";  
            cssLink.Attributes["href"] = url;  
            if (!string.IsNullOrEmpty(url))