The Controls collection cannot be modified because the control contains code blocks

   —   
This article will explain how to avoid the "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)" error message on your site.
This error occurs because the page (page layout, web part code) contains code blocks which are not resolved correctly in some special cases.  The example below shows how to avoid this issue and how to use the code in a layout in the proper way:

<asp:Literal runat="server" ID="test" Text="test" />

<script runat="server">
protected void Page_PreRender(object sender, EventArgs e)
{
test.Text = CMS.GlobalHelper.ResHelper.GetString("general.ok");
}
</script>
-jo-


See also: Forum thread 1
F
orum thread 2

Applies to: Kentico CMS 6.x, 7.x
Share this article on   LinkedIn Google+

Juraj Ondrus

Hi, I am the Technical support leader at Kentico. I'm here to help you use Kentico and get as much as possible out of it.