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.AddAt(Int32 index, Control child) +8668018
Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) +133
[HttpException (0x80004005): Please, see whether wrapping the code block, generating the exception, within RadCodeBlock resolves the error.]
Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) +181
Telerik.Web.UI.RadAjaxControl.PerformRender() +375
Telerik.Web.UI.RadAjaxControl.OnPageRender(HtmlTextWriter writer, Control page) +1222
Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) +95
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
3
votes
3 Answers
2
votes
2
votes
0
votes
In my case, I had few if-else blocks inside the ASPX page like below.
<%if (showControl)
{%>
<%--HTML Markup--%>
<%}%>
I wrapped each inside a RadCodeBlock
and the error went away.
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<%if (showControl)
{%>
<%--HTML Markup--%>
<%} %>
</telerik:RadCodeBlock>
Had to wrap each such block inside a RadCodeBlock. Tried wrapping the entire html body, but that didn't work.