More in this section
Forums / Suggestions / cssfilelink check for duplicates

cssfilelink check for duplicates

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    18 Jul 2012
    26 Nov 2008
    Link to this post
    i am using the cssfilelink control in a user control to ensure that any page that uses that control will have the associated css file loaded...

    however, if a user places multiple instances of this control on a page, then the css file is loaded twice! It would be helpful if the filelink can somehow 'check' if the css file has already been queued up and if so, bypass adding it to the header.

    declaring the css in the page is not a viable solution because the css is associated with the control, regardless of what page it is on, and the control will require the css be set on any page it is on.

    any advice is appreciated, thanks!
  2. Pepi
    Pepi avatar
    981 posts
    31 Jan 2017
    27 Nov 2008
    Link to this post
    Hello SelArom,

    Definitely, we will consider your suggestion for future versions of Sitefinity. In the meantime, you could implement your own control that extends CssFileLink class like this:

    using System; 
    using System.Data; 
    using System.Configuration; 
    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 Telerik.Cms.Web.UI; 
    namespace Telerik.Cms.Web.UI 
        public class CssFileLinkFix : CssFileLink 
            protected override void CreateChildControls() 
                if (!IsAdded(this.FileName)) 
            private bool IsAdded(string href) 
                foreach (Control ctrl in this.Page.Header.Controls) 
                    if (ctrl is HtmlGenericControl) 
                        HtmlGenericControl genericCtrl = (HtmlGenericControl)ctrl; 
                        if (genericCtrl.TagName == "link" && genericCtrl.Attributes["href"] == ResolveUrl(href)) 
                            return true
                return false

    Then you should use CssFileLinkFix instad of CssFileLink:

    <%@ Register Assembly="App_Code" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %> 
     <sfWeb:CssFileLinkFix ID="CssFileLinkFix1" runat="server" FileName="~/Sitefinity/ControlTemplates/CommonLayout.css" Media="screen" /> 

    Hope this helps.

    Sincerely yours,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered