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

25 posts, 0 answers
  1. Will
    Will avatar
    30 posts
    Member since:
    Aug 2008

    Posted 03 Aug 2009 Link to this post

    We are getting this error when the following code is added to a User Control:
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="JawbCategoryComboBox">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="JawbOccupationComboBox" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 

    It is the <telerik:AjaxUpdatedControl> line that is causing the issue.  If I comment it out, the error goes away.  I read the other posts about code within the <head> tags, but the only code in the <head> section is stylesheet code.  There aren't any <% %> tags anywhere in the <head> section of the master page or any of the children.  Here is the exact error:


    [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) +8669270
       Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) +132

    [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) +180
       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


    What else causes this error?

    Thanks,
    Bill

  2. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 03 Aug 2009 Link to this post

    Hello Bill,

    Could you please try to wrap your JavaScript code (no matter whether it is in the head section or not) in RadCodeBlock as depicted in the following article?

    RadCodeBlock and RadScriptBlock


    Best regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Will
    Will avatar
    30 posts
    Member since:
    Aug 2008

    Posted 03 Aug 2009 Link to this post

    Hey Daniel,

    There isn't any JavaScript code in the entire site that is not managed by the script processors, so it would be impossible to wrap it in those blocks as none of the code exists in the .aspx or .ascx files.  Everything is managed.

    Thanks,
    Bill
  5. Will
    Will avatar
    30 posts
    Member since:
    Aug 2008

    Posted 03 Aug 2009 Link to this post

    I went back to look and there was one JavaScript code block for the Microsoft pubCenter code.  I wrapped the block in <telerik:RadCodeBlock> tags, but it had no effect.  The page still errors out.  Is there any kind of trace or debug mode to find out exactly what it is erroring out on?
  6. Will
    Will avatar
    30 posts
    Member since:
    Aug 2008

    Posted 04 Aug 2009 Link to this post

    I figured out how to work around the issue, but it makes absolutely no sense at all.  It appears that any <% ... %> contents (including data bind controls, but not comments) will cause this issue unless it is the child of another control, with the exception of some non-repeater templated controls (i.e. UpdatePanels).  For example, if the parent server control is an UpdatePanel, moving it inside of a Label will fix the problem.  This is definitely a bug in the Telerik AjaxManager as this is not a limitation of ASP.NET AJAX.

    The really bad thing about it is that there is absolutely no useful information in the error message to let you know what to look for.  I spent the last 3 days trying to find a single control that was causing the the issue.  This needs to be fixed.
  7. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 06 Aug 2009 Link to this post

    Hello Bill,

    Thank you for the explanation.

    Could you please post a simple code-snippet that demonstrates the issue? We would like to investigate the behavior you depicted.

    Best regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. Jacques
    Jacques avatar
    135 posts
    Member since:
    Jun 2007

    Posted 05 Sep 2009 Link to this post

    Hi Daniel,

    Not sure if this issue was sorted out, but I'm having the same behavior.

    The portion of the RadAjaxManager that causes the problem is here:
    <telerik:AjaxSetting AjaxControlID="QuickAddButton"
        <UpdatedControls> 
            <telerik:AjaxUpdatedControl ControlID="FarmsRadGrid" LoadingPanelID="FarmGridLoading" /> 
            <telerik:AjaxUpdatedControl ControlID="FarmsObjectDataSource" /> 
            <telerik:AjaxUpdatedControl ControlID="PageLoadErrorPopup" /> 
            <telerik:AjaxUpdatedControl ControlID="FarmNameRadTextBox" /> 
        </UpdatedControls> 
    </telerik:AjaxSetting> 

    The last AjaxUpdatedControl is a simple RadTextBox, but when I added it I got the same error as mentioned by Bill. Looking at his posts I went and added a <span runat="server"> around the RadTextBox in question and this solved the problem.
    <span runat="server"
            <telerik:RadTextBox ID="FarmNameRadTextBox" runat="server" SelectionOnFocus="SelectAll" 
                Width="181px" EmptyMessage="[farm name...]" InvalidStyleDuration="100" LabelCssClass="radLabelCss_Vista"
            </telerik:RadTextBox> 
    </span> 

    Why would this be happening? Before adding the server span element it wouldn't work, if I remove it the error comes back. It's just this control that causes the problem. I have quite a few other controls referenced in the AjaxManager and none of them caused this problem.

    Regards,
    Jacques
  9. Will
    Will avatar
    30 posts
    Member since:
    Aug 2008

    Posted 06 Sep 2009 Link to this post

    Hey Jacques,

    It is an issue with RadAjaxManager, and it still exists.  I looked into the problem further, and the problem is with the way that they are wrapping the control dynamically with an UpdatePanel.  If the ControlID attribute of an AjaxUpdatedControl element references anything other than an UpdatePanel, that control is dynamically wrapped with an UpdatePanel, which is what is causing the problem.  Simply wrapping the <% ... %> code within any server control allows you to work around the problem, which is what you observed.  I'm hoping that it will be fixed soon, as the error messages often point you to the wrong section of code.

    Take it easy,
    Bill
  10. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 22 Sep 2009 Link to this post

    Hi,
    Is there still no real fix for this?

    I have a drag-and-drop example working fine on a test-page that uses my master page, but as soon as I try to use the code (and the RadAjaxManager) on a "real" page in my site, it blows up with the cited error. I've tried the workarounds noted in this forum, to no avail. I'm suspecting my ASP.NET Localization, where I have tags like LoadingText="<%$ Resources:resources, LoadingFromSvrLbl %>"  ALL OVER THE PLACE. I cannot possibly put all of the localization code inside RadCodeBlocks. The error messages do not point to anything intelligible. It is like looking for a needle in an hay stack. A real pain... and a disappointment.

    Any tips?

    Thanks!
    R
  11. Will
    Will avatar
    30 posts
    Member since:
    Aug 2008

    Posted 22 Sep 2009 Link to this post

    Hey Richard,

    At this time, there is no other option.  It took me about 4 hours to wrap every single <% Resources... %> tag in one site, so I know what you are going through.  Unfortunately, you will need to do it if you want to use the controls.

    Take it easy,
    Bill
  12. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 22 Sep 2009 Link to this post

    Thanks Bill,

    This:

    http://www.aspnetresources.com/blog/code_blocks_inside_master_pages_cause_trouble

    and a few judiciously applied RadCodeBlocks in my MasterPage did the trick. Not the prettiest thing in the world, but what the heck.

    Best regards,
    Richard




  13. Yeroon
    Yeroon avatar
    87 posts
    Member since:
    Oct 2012

    Posted 05 Oct 2009 Link to this post

    Hi,

    I had the same error message, but with a  different cause. Mine was caused because I accidently removed the <form runat="server" id="form1"> tag.

    The compiler had no trouble with the missing tag, but when running it gave the error mentioned in the startingpost.
  14. Tony
    Tony avatar
    3 posts
    Member since:
    Apr 2010

    Posted 06 May 2010 Link to this post

    Did this ever get resolved?  Seems like I ran into this issue right now.  
  15. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 07 May 2010 Link to this post

    Hello Tony,

    Can you please post/attach some code so we can examine your approach?

    In the meantime I recommend you examine the following blog post by Rick Strahl:
    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Regards,
    Daniel
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  16. Joaquín
    Joaquín  avatar
    1 posts
    Member since:
    Feb 2009

    Posted 11 May 2010 Link to this post

    Hi, same problem here!..

    I have a master/content page, same error... here is the code of my content page:

    Does the SqlDataSource cause the problem??

    <asp:Content ID="Content1" ContentPlaceHolderID="CPH1" Runat="Server"
     
        <script type="text/javascript"
            function GetRadWindow() { 
                var oWindow = null
                if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog 
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well) 
     
                return oWindow; 
            } 
         function Close() { 
            GetRadWindow().close(); 
        } 
     
        //Se llama a la función que recarga el grid y se cierra la ventana secundaria 
        function CloseAndRebind() { 
            GetRadWindow().BrowserWindow.refreshGrid(); 
            GetRadWindow().close(); 
        } 
         
    </script> 
     
     <asp:SqlDataSource ID="DataSourceSistema" runat="server" ConnectionString="<%$ ConnectionStrings:SqlConnectionString %>"  
        SelectCommand="SELECT * FROM [sistema_computacional] ORDER BY [nombre]" OldValuesParameterFormatString="original_{0}"
       </asp:SqlDataSource> 
        <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="Panel1"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="Panel1"  
                            LoadingPanelID="RadAjaxLoadingPanel1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManagerProxy> 
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server"  
            Skin="Default"
        </telerik:RadAjaxLoadingPanel> 
        <asp:Panel ID="Panel1" runat="server"
    <table style="width: 100%" cellpadding="0" cellspacing="0"
            <tr> 
                <td style="text-align: left; width: 147px;" class="etiqueta"
                    Nombre:</td> 
                <td> 
                    <telerik:RadTextBox ID="txtBoxNombre" Runat="server"  
                        EmptyMessage="No hay un nombre asignado al componente" Width="425px"
                    </telerik:RadTextBox> 
                    &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  
                        ControlToValidate="txtBoxNombre" ErrorMessage="Campo requerido"></asp:RequiredFieldValidator> 
                </td> 
            </tr> 
            <tr> 
                <td style="text-align: left; width: 147px;" class="etiqueta"
                    Descripción:</td> 
                <td> 
                    <telerik:RadTextBox ID="txBoxDescripcion" Runat="server"  
                        EmptyMessage="Indique una descripción para el componente" Rows="5"  
                        TextMode="MultiLine" Width="425px"
                    </telerik:RadTextBox> 
                    &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"  
                        ControlToValidate="txBoxDescripcion" ErrorMessage="Campo requerido"></asp:RequiredFieldValidator> 
                </td> 
            </tr> 
            <tr> 
                <td style="text-align: left; width: 147px;" class="etiqueta"
                    Sistema:</td> 
                <td> 
                    <telerik:RadComboBox ID="rboxSistema" Runat="server"  
                        DataSourceID="DataSourceSistema" DataTextField="nombre"  
                        DataValueField="clave_sistema" Filter="Contains" AutoPostBack="True"  
                        ValidationGroup="none" Width="300px"
                    </telerik:RadComboBox> 
                    &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"  
                        ControlToValidate="rboxSistema" ErrorMessage="Campo requerido"></asp:RequiredFieldValidator> 
                </td> 
            </tr> 
            <tr> 
                <td style="text-align: left; width: 147px;" class="etiqueta"
                    Tipo de Componente:</td> 
                <td> 
                    <telerik:RadComboBox ID="rboxTipoComponente" Runat="server"  
                        EmptyMessage="No existen tipos de componentes para este sistema"  
                        Filter="Contains" ValidationGroup="none" Width="350px"
                    </telerik:RadComboBox> 
                    &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"  
                        ControlToValidate="rboxTipoComponente" ErrorMessage="Campo requerido"></asp:RequiredFieldValidator> 
                </td> 
            </tr> 
            <tr> 
                <td style="text-align: left; width: 147px;" class="etiqueta"
                    Componente Activo:</td> 
                <td> 
                    <asp:CheckBox ID="ckbActivo" runat="server" /> 
                </td> 
            </tr> 
            <tr> 
                <td style="text-align: left; font-weight: 700; " colspan="2"
                    <table style="width: 100%" cellpadding="1" cellspacing="0"
                        <tr> 
                            <td style="text-align: left; width: 147px;" class="etiqueta"
                    Archivos Asociados:</td> 
                            <td> 
                                <telerik:RadTextBox ID="txtBoxNewArchivo" Runat="server" Width="225px"  
                                    ValidationGroup="archivos"
                                </telerik:RadTextBox> 
    &nbsp;<asp:Button ID="btnAgregar" runat="server" Text="Agregar" CssClass="BotonAzul"  
                                    ValidationGroup="archivos" /> 
                                &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"  
                                    ControlToValidate="txtBoxNewArchivo" ErrorMessage="Se requiere un nombre"  
                                    ValidationGroup="archivos"></asp:RequiredFieldValidator> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td colspan="2" style="text-align: left"
                                <table cellpadding="0" cellspacing="0" style="width: 100%"
                                    <tr> 
                                        <td style="text-align: left; width: 147px;"
                                            &nbsp;</td> 
                                        <td style="font-size: small; text-align: center" width="3%"
                                            <b>Activo</b></td
                                        <td> 
                                            &nbsp;</td> 
                                    </tr> 
                                    <tr> 
                                        <td> 
                                            &nbsp;</td> 
                                        <td colspan="2"
                                <telerik:RadListBox ID="radListArchivos" runat="server" AllowDelete="True"  
                                    CheckBoxes="True" style="text-align: left" Height="125px"  Width="400px"
    <ButtonSettings TransferButtons="All"  AreaWidth="90px" RenderButtonText="True"  VerticalAlign="Middle"></ButtonSettings> 
                                </telerik:RadListBox> 
                                        </td> 
                                    </tr> 
                                </table> 
                            </td> 
                        </tr> 
                    </table> 
                </td> 
            </tr> 
            <tr> 
                <td style="text-align: right; font-weight: 700; width: 147px; height: 30px;"
                    </td> 
                <td style="text-align: right; height: 30px;"
                    <asp:Label ID="lblError" runat="server" style="color: #CC0000" ></asp:Label> 
                    <asp:Button ID="btnGuardar" runat="server" Text="Guardar"  
                        CssClass="BotonAzul" /> 
                    <input id="Button1" class="BotonAzul" type="button" value="Cancelar" onclick="javascript: Close(); return false;" /></td
            </tr> 
            </table> 
                </asp:Panel> 
          <% =strJavascript%> 
    </asp:Content> 
     

  17. Lubna Ansari
    Lubna Ansari avatar
    65 posts
    Member since:
    Feb 2010

    Posted 27 Oct 2010 Link to this post

    Hi,
    Is this issue resolved in new version. I am using 2010.2.713.35.

    Regards,
    Lubna.
  18. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 27 Oct 2010 Link to this post

    Hi Lubna,

    I am afraid the issue has not been fixed, because the causes of its occurrence remain the same.

    When you add a code block to a web page, the page parser will use a SetRenderMethodDelegate, which in turn will make the controls collection of the code block's parent read-only.

    On the other hand, in order to add update panels on the fly, RadAjax inserts a dummy control before and after the control to be ajaxified. This is needed because the ajaxified control cannot be reparented (which will occur if an update panel is inserted in the page just like that). If this dummy control injection happens in a read-only control collection, you will receive the observed error.

    The solution for the problem is to use code blocks inside a telerik:RadCodeBlock control, as explained in the previous posts.

    Regards,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  19. Stuart Tlrk
    Stuart Tlrk avatar
    3 posts
    Member since:
    Mar 2012

    Posted 13 Mar 2012 Link to this post

    This resolved the issue for me ... I had <% Resolve ... %> tags in my <head> block on my master page. http://aspnetresources.com/blog/code_blocks_inside_master_pages_cause_trouble
  20. Godisang
    Godisang avatar
    1 posts
    Member since:
    Jun 2012

    Posted 08 Aug 2012 Link to this post

    Removing the commented out source in the .aspx file and adding scripts to the codeblock solved this for me.
  21. Tim
    Tim avatar
    85 posts
    Member since:
    Aug 2008

    Posted 19 Apr 2013 Link to this post

    So basically, the moral of the story is stick with the old tried-and-true MS UpdatePanel?  What am I getting by using a RadAjaxPanel?  Sorry if this has been answered before, but I am new to this version of the controls.
  22. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 24 Apr 2013 Link to this post

    Hi Tim,

    You could continue using RadAjaxManager and RadAjaxPanel controls and simply wrap all the script blocks into RadScriptBlock or RadCodeBlock controls. See the help topic below:
    http://www.telerik.com/help/aspnet-ajax/ajax-radscriptblock-radcodeblock.html

    All the best,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  23. Tim
    Tim avatar
    85 posts
    Member since:
    Aug 2008

    Posted 24 Apr 2013 Link to this post

    I have already figured out another way around it without those things.  See my post here...
  24. Siraj
    Siraj avatar
    1 posts
    Member since:
    Sep 2013

    Posted 04 Sep 2013 Link to this post

    hi all,

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

    As Will and Hoventer.J says
    This error can be solved  by put enclose <span runat="server"> </span>
    for example <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                        <AjaxSettings>
                            <telerik:AjaxSetting AjaxControlID="RadComboBox_Owner_Name">
                                <UpdatedControls>
                                    <telerik:AjaxUpdatedControl ControlID="RadComboBox_Owner_Name" />
                                </UpdatedControls>
                            </telerik:AjaxSetting>
    </telerik:RadAjaxManager >

    we have to
    <span runat="server">
    <telerik:RadComboBox ID="RadComboBox_Owner_Name" runat="server" AllowCustomText="false" ShowMoreResultsBox="true" >
                                </telerik:RadComboBox> </span>
    I tried on master page,radscriptblock,codeblock method nothings happen,atlast span works....

    Thanks for writing......


  25. Manuel Buendia
    Manuel Buendia avatar
    5 posts
    Member since:
    Mar 2011

    Posted 09 Sep 2013 Link to this post

    Try the next order 

    1.-telerik:RadAjaxManager 
    2.-telerik:RadScriptManager
    3.-telerik:RadAjaxLoadingPanel 

    its all
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                       <AjaxSettings>
                           <telerik:AjaxSetting AjaxControlID="RadGrid1" >
                               <UpdatedControls>
                                   <telerik:AjaxUpdatedControl ControlID="RadGrid1"  LoadingPanelID="RadAjaxLoadingPanel1"/>
                               </UpdatedControls>
                           </telerik:AjaxSetting>
                       </AjaxSettings>
                   </telerik:RadAjaxManager>
                 
                   <br />
               <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
     
              <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Telerik"></telerik:RadAjaxLoadingPanel>
  26. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 10 Sep 2013 Link to this post

    Hello,

    @Manuel Buendia

    1.-telerik:RadScriptManager/asp:ScriptManager
    2.-telerik:RadAjaxManager
    3.-telerik:RadAjaxLoadingPanel 

    As per .net Framework if we used any ajax control, then we have add scriptmanager before use of any ajaxcontrol.


    @Siraj

    If you used "<%= %> or <%# %>" in your page then put this code in to RadcodeBlock.

    1. Please put your JavaScript code in to RadCodeBlock
    2. Ex: if you assign any property in to span/div/label/tr in aspx page then put this code into RadCodeBlock.

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
           <span>
               <%= YourPropertyName %>
           </span>
       </telerik:RadCodeBlock>


    Thanks,
    Jayesh Goyani
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017