The Controls collection cannot be modified

4 posts, 0 answers
  1. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 20 Aug 2008 Link to this post

    I am running into an issue with the RadAjaxManager and receiving the *incredibly* annoying .Net error (why they care is beyond me):

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

    Below is my AjaxManager control markup. The error only occurs when I set EnableAjax to True. If it is False, the error doesn't show up.

    Below is my AjaxManager control markup. The error only occurs when I set EnableAjax to True. If it is False, the error doesn't show up.
    1     <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" EnableAJAX="true" EnableHistory="true" OnAjaxRequest="RadAjaxManager1_AjaxRequest">  
    2         <AjaxSettings> 
    3             <telerik:AjaxSetting AjaxControlID="radFolders" EventName="radFolders_OnNodeClick">  
    4                 <UpdatedControls> 
    5                     <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadGridLoadingPanel" /> 
    6                 </UpdatedControls> 
    7             </telerik:AjaxSetting> 
    8             <telerik:AjaxSetting AjaxControlID="radFolders" EventName="radFolders_OnNodeEdit">  
    9                 <UpdatedControls> 
    10                     <telerik:AjaxUpdatedControl ControlID="radFolders" LoadingPanelID="RadTreeViewLoadingPanel1" /> 
    11                 </UpdatedControls> 
    12             </telerik:AjaxSetting> 
    13             <telerik:AjaxSetting AjaxControlID="radFolders" EventName="radFolders_OnContextMenuItemClick">  
    14                 <UpdatedControls> 
    15                     <telerik:AjaxUpdatedControl ControlID="radFolders" LoadingPanelID="RadTreeViewLoadingPanel1" /> 
    16                 </UpdatedControls> 
    17             </telerik:AjaxSetting> 
    18         </AjaxSettings> 
    19     </telerik:RadAjaxManager> 
    20  


    The weirdest part about this is the fact that the above control clearly shows no code blocks exist, and in fact the only one that is on the entire page can be taken out and the error still comes up. Since I have the source code I have linked your project to mine and the error is showing up here:

    Line 880:            int updatedLocation = controls.IndexOf(updated);
    Line 881:
    Line 882: controls.AddAt(updatedLocation, pre);Line 883:
    Line 884:            PostControlToAjaxify post = new PostControlToAjaxify(updated);

    Source File: C:\dev\components\telerik.web.ui\06.19.2008\Ajax\RadAjaxControl.cs    Line: 882

    Any suggestions as to what might cause this?
  2. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 21 Aug 2008 Link to this post

    Hi digitall,

    The error is caused by any code blocks (i.e. <% ... %>) on the page and not in a certain control only. You can isolate those code blocks in a RadCodeBlock control to resolve the error.

    All the best,
    Konstantin Petkov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 21 Aug 2008 Link to this post

    That's what I thought too because you guys helped me with the error in the past. The confusing part is that the only line that has anything like that looks like this: <h1>Welcome, <%= User.Identity.Name %> and it isn't contained in any type of AJAX control. It is simply embedded on the page at the top. I put it into the ScriptBlock and it resolved the error, but I'm confused why this was an issue at all. I wasn't trying to modify this via AJAX in any form (or via any method actually). Why would the parser care about something like this?
  5. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 21 Aug 2008 Link to this post

    Hello digitall,

    Unfortunately this is the way the page parser is implemented. RadAjaxManager wraps the controls set as updated into UpdatePanels thus changing the controls structure on the page. Whenever that happens though, the page parser gets those code blocks and throws the error if those are not isolated.

    This is pretty nasty I must agree but the manual isolation of the code blocks is the best workaround we've found so far. We are sorry for the caused inconvenience.

    Greetings,
    Konstantin Petkov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top