I've been using Web Forms for Marketers (WFFM) in a Sitecore project recently and I noticed that it injected:
<link href="/sitecore%20modules/shell/Web%20Forms%20for%20Marketers/themes/colors//jquery-ui.custom.Default.css" rel="stylesheet" type="text/css" />
Is there a way to disable the link so that only CSS files that I've specified are added to the page?
After reviewing more of the WFFM source, I've noticed that the unwanted <link />
is added to the page via Page.Header.Controls
:
if (page.Header != null)
{
if (!flag)
{
try
{
//possibly added as link, unless an exception is thrown
page.Header.Controls.Add((Control) htmlLink);
linkDictionary.Add(key, key);
continue;
}
catch (Exception ex)
{
//added manually
HtmlTextWriter writer = new HtmlTextWriter((TextWriter) new StringWriter(new StringBuilder()));
htmlLink.RenderControl(writer);
page.ClientScript.RegisterClientScriptBlock(typeof (Page), writer.InnerWriter.ToString(), writer.InnerWriter.ToString());
flag = true;
continue;
}
}
}
Which means I could check all the header controls and hide the one that contains "jquery-ui.custom.Default.css"
, but this still feels like a dirty-nasty-hack (which it is). It also wont remove the link in situations where page.Header.Controls.Add
would throw an exception.
Web Forms for Marketers will, in fact, not add the <link>
tag if the stylesheet is not present in the filesystem.
The underlying issue turned out to be that TDS had cached a copy of the removed stylesheet, and was adding it to the web directory on every build. Cleaning the build and making sure to clear the cached TDS files fixed the issue without needing to add server side code.