This is a migrated thread and some comments may be shown as answers.

The Controls collection cannot be modified

3 Answers 194 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
digitall
Top achievements
Rank 1
digitall asked on 21 Aug 2008, 02:15 AM

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.
    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" EnableAJAX="true" EnableHistory="true" OnAjaxRequest="RadAjaxManager1_AjaxRequest">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="radFolders" EventName="radFolders_OnNodeClick">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadGridLoadingPanel" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="radFolders" EventName="radFolders_OnNodeEdit">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="radFolders" LoadingPanelID="RadTreeViewLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="radFolders" EventName="radFolders_OnContextMenuItemClick">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="radFolders" LoadingPanelID="RadTreeViewLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
 


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?

3 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 21 Aug 2008, 06:14 AM
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.
0
digitall
Top achievements
Rank 1
answered on 21 Aug 2008, 12:15 PM
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?
0
Konstantin Petkov
Telerik team
answered on 21 Aug 2008, 02:16 PM
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.
Tags
Ajax
Asked by
digitall
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
digitall
Top achievements
Rank 1
Share this question
or