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 %>
          </h1>
      </span>
  </div>
</div>

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

Hi,

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

Recent Answers


Tim Ramage answered on October 4, 2016 20:40

If you wrap your code in an <asp:PlaceHolder /> control, it will fix the issue.

3 votesVote for this answer Mark as a Correct answer

Tommy De Notarpietro answered on October 18, 2016 09:29

By using the placeholder, like Tim says, it resolved the issue for me.

0 votesVote for this answer Mark as a Correct answer

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