7

After upgrading from Sitecore 8.1 to 8.2, we continue to see the following error when working in CM. Users can login and begin working in Sitecore, but after a random amount of time, they get the the error. The only way to clear the error is to close the browser.

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

Server Error in '/' Application.

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: [HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).] System.Web.UI.ControlCollection.Add(Control child) +11843103 Sitecore.MediaFramework.Pipelines.RenderLayout.RenderLayoutBase.Render(RenderLayoutArgs args) +256 Sitecore.MediaFramework.Pipelines.RenderLayout.RenderLayoutBase.Process(RenderLayoutArgs args) +108 (Object , Object[] ) +174 Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +479 Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22 Sitecore.Layouts.PageContext.BuildControlTree(Object sender, EventArgs e) +214 System.Web.UI.Page.OnPreInit(EventArgs e) +11869081 System.Web.UI.Page.PerformPreInit() +46 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1120

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0

  • ajones have you tried getting the base install zip package and using winmerge (or similar diff tool) to compare your solution with that for differences? you might be missing some of the required files. – Adam Seabridge Nov 23 '17 at 13:11
  • 2
    What is the url when on one of these error pages? Is it http://domain/sitecore/login?someQuery=string? – Teeknow Nov 25 '17 at 6:28
  • i saw it before when happens when the user session expired , please check if that is the case here – Naim Alkouki Feb 7 '18 at 19:18
  • @Teeknow yes, I just found the same issue now. Do you have any solution for that? – Tamás Tárnok Feb 12 '18 at 15:26
  • 1
    @TamásTárnok yes this seemed to work for me: sitecore.stackexchange.com/a/8465/1436. You might need to ask support for whichever version of Sitecore you have. – Teeknow Feb 12 '18 at 20:34
1

Without seeing your code it is hard to say for certain what is going on however this is typically caused by using code blocks in a Sitecore layout. This will work fine in the Content Editor however as soon as you go to use the Page Editor or Preview a page you will run into this error. This happens because Sitecore dynamically adds the ribbon control to the page which modifies the controls collection.

There are a few options here for solving this issue:

  • Use a literal control or a repeater if possible
  • If trying to inject something into your JavaScript (e.g. the ClientID of a field) then do so using Page.ClientScript.RegisterClientScriptBlock.
  • Use a data binding block instead (<%# %>)

References:

http://www.tcsc.com/sitecore-layouts-and-code-blocks/ https://weblogs.asp.net/abdullaabdelhaq/how-to-fix-this-the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-i-e-lt-gt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.