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

2 posts, 1 answers
  1. Marcel Rossi
    Marcel Rossi avatar
    9 posts
    Member since:
    Jul 2007

    Posted 12 Mar 2010 Link to this post

    Hi

    I had the following Server Error after including a RadAjaxManager to a Webpage:

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    In many forums they said to be sure to remove all code blocks (<% %>) in the Head-Section of the Page.
    Or delete the runat="server" from the Head-Section.

    Noting helped in my case. But the ting with the code blocks helped me find it out.
    It had nothing to do with the Head-Section of the Page or the Master-Page.

    I simply had to remove the code blocks IN my page.

    That's the page-code that produces the Error:
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="CollectionModifyProblem._Default" %> 
     
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml" > 
     
    <head runat="server">  
     
    <title>Untitled Page</title> 
     
    </head> 
     
    <body> 
     
    <form id="form1" runat="server">  
     
     
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
     
    </telerik:RadScriptManager> 
     
     
    <div> 
     
     
    <%="Select a Brand (norally I use a var here):"%> 
     
    <telerik:RadListBox ID="lstbBrands" runat="server"></telerik:RadListBox> 
     
     
    <%="Select a Type: (norally I use a var here)"%> 
     
    <telerik:RadListBox ID="lstbCarTypes" runat="server"></telerik:RadListBox> 
     
     
    </div> 
     
     
    <telerik:RadAjaxManager runat="server">  
     
    <AjaxSettings> 
     
    <telerik:AjaxSetting AjaxControlID="lstbBrands">  
     
    <UpdatedControls> 
     
    <telerik:AjaxUpdatedControl ControlID="lstbCarTypes" /> 
     
    </UpdatedControls> 
     
    </telerik:AjaxSetting> 
     
    </AjaxSettings> 
     
    </telerik:RadAjaxManager> 
     
     
    </form> 
     
     
    </body> 
     
    </html> 

    After a while I replaced the two code-blocks with labels:

    <%="Select a Brand (norally I use a var here):"%> 
    to  
    <asp:Label runat="server" ID="lblTitle_Brands">Select a Brand (noraly I fill this by code):</asp:Label> 

    and

    <%="Select a Type (norally I use a var here):"%> 
    to  
    <asp:Label runat="server" ID="lblTitle_Type">Select a Type (noraly I fill this by code):</asp:Label> 

    That's all you have to do!

    Maybe this will help also others!

    Freundliche Grüsse
    Marcel

  2. Answer
    robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 13 Mar 2010 Link to this post

    Technically, the actual solution would be to enclose your code blocks inside the RadScriptBlock control when using RadAjaxManager.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top