Reputation: 179264
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.
Upvotes: 5
Views: 2468
Reputation: 179264
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.
Upvotes: 3
Reputation: 31435
I've de-compiled WFFM and it doesn't appear to be configurable to change it or turn it off. So, one way to get around this issue is to edit this file directly and wipe out its contents. It will still be loaded but won't include any CSS.
UPDATE
Per your updates, you could also try something like this:
Control ctl = WebUtil.FindControlOfType(Sitecore.Context.Page.Page, typeof(TYPE-OF-EXPECTED-CONTROL));
Where you replace TYPE-OF-EXPECTED-CONTROL
. From here you can do whatever you want with it, e.g. figure out if its the link to include the CSS, etc.
Upvotes: 3