Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent web forms for marketers from injecting its own jquery-ui.custom.Default.css

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.

like image 459
zzzzBov Avatar asked Feb 14 '12 18:02

zzzzBov


1 Answers

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.

like image 59
Mark Ursino Avatar answered Oct 13 '22 22:10

Mark Ursino