Search code examples
.netteleriksquishit

Use SquishIt and get 'Controls collection cannot be modified because the control contains code blocks' error


I am writing a .net 2.0 website project and had been happily using SquishIt for some time to minify and combine by CSS and Javascript. I recently starting getting this error :

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 

HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.Add(Control child) +11035338
   Telerik.Web.SkinRegistrar.RegisterCssReference(Page _page, Control _control, String _url) +413

[HttpException (0x80004005): Please, see whether wrapping the code block, generating the exception, within RadCodeBlock resolves the error.]
   Telerik.Web.SkinRegistrar.RegisterCssReference(Page _page, Control _control, String _url) +533
   Telerik.Web.SkinRegistrar.RegisterCssReferences(ISkinnableControl _control) +828
   Telerik.Web.UI.RadComboBox.OnPreRender(EventArgs e) +32
   System.Web.UI.Control.PreRenderRecursiveInternal() +108
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394

As you can see we are also using Telerik controls within the site so I suspect this is the issue.

I tried using the SquishIt API to call the Add and Render commands from code behind but it didn't produce any results at all.

Any ideas? I'd rather not abandon SquishIt as it performs great otherwise.


Solution

  • I found the solution. It turns out that when you are using Telerik Rad controls within your site and if you have any code blocks in the header of your master pages then you need to include a special Telerik code block tag.

    With this tag in place I can now use SquishIt without error!