The Controls collection cannot be modified... error

Vic Alfred Inting asked on December 15, 2014 06:55

I'm trying to setup my templates such that pages render the document name onto the Page banner section. Here is my code on the page template:

<div class="row show-grid">
    <div class="col-md-12 page-banner">
        <span class="show-grid-block">
          <img src="/happy-tails/media/Assets/Images/dog-beagle.jpg" style="width: 100%; height: auto;">
          <h1 class="page-title">
            <%= CMSContext.CurrentDocument.DocumentName %>

It works on most of my pages but I have a specific template being used by 2 pages that gives this server error when I apply the above:

There was an error processing the page. The error can be caused by the configuration of some component on the master page. Check the master page configuration or see event log for more details. Original message: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %).

Anyone have any ideas why this is happening? Thanks!

Correct Answer

Juraj Ondrus answered on December 15, 2014 09:57


This depends on the order when this code is loaded. It depends what other web parts are on the page. Since it is not possible to ensure the same loading order all the time, the solution is described in this article.

Best regards,
Juraj Ondrus

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.