If you find yourself with an elusive “The controls collection cannot be modified” error, we’ve figured out some details that might help. The docs (http://www.telerik.com/help/aspnet-ajax/ajxmigration.html) state that you need to add a RadCodeBlock around all <script> tags that have a <%= somewhere in them.
Via a support ticket, we learned that all <%= tags need a RadCodeBlock. Adding RadCodeBlocks throughout an application any larger than a small website can be a daunting task. In our application, on a single page, I ended up finding two particular <%= tags that needed a RadCodeBlock.
But what really got us thinking was all the ones that did not need a RadCodeBlock. As we looked, what we found was that when a <%= was contained within a control that was runat=”server”, it did not need a RadCodeBlock. All the RadCodeBlock does is give you a container control that is runat=”server”
Here’s an example of a place which threw the “The controls collection cannot be modified…” error:
<fieldset>
<legend>
<%=Resources.Atlas.Recipients%>
</legend>
Simply adding ‘runat=”server”’ to the legend tag fixes the problem.
<fieldset>
<legend runat="server">
<%=Resources.Atlas.Recipients%>
</legend>
Note however, that it is not adequate to add the runat=”server” to the fieldset tag. The immediate parent MUST be runat=server.
It seems that a good regular expression or a simple little application that parses aspx/ascx files could easily find every location where you need to add a runat="server" to an immediate parent.Warmest Regards,
Matt