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

53 posts, 0 answers
  1. Jason Maronge
    Jason Maronge avatar
    322 posts
    Member since:
    Jan 2005

    Posted 24 Apr 2007 Link to this post

    I am trying to change to the new AjaxManager and AjaxPanel and right off the bat I am getting the following error:

    Source: System.Web
    Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
    Inner Exception: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
    Stack Trace: at System.Web.UI.ControlCollection.AddAt(Int32 index, Control child) at Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) at Telerik.Web.UI.RadAjaxControl.PerformRender() at Telerik.Web.UI.RadAjaxControl.OnPageRender(HtmlTextWriter writer, Control page) at Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Page.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    Form:
    Query String:
    Target Site: Boolean HandleError(System.Exception)


    All i have done is change the radA:RadAjaxPanel to telerik:RadAjaxPanel.  I also added the <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> tag to the top of the page.  I also put a ScriptManager on the page.  Is there something I missed?

    Thanks,  Jason

  2. RichJ
    RichJ avatar
    83 posts
    Member since:
    Aug 2006

    Posted 24 Apr 2007 Link to this post

    Hi Jason,

    Try removing the runat=server from the <head> tag in your document.
    I've just resolved this with a standard RAD ASP.NET control.

    Rich
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 25 Apr 2007 Link to this post

    Hello Jason,

    If you have any code blocks you can enclose them using telerik:RadCodeBlock tag.

    Best regards,
    Vlad
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Jason Maronge
    Jason Maronge avatar
    322 posts
    Member since:
    Jan 2005

    Posted 25 Apr 2007 Link to this post

    I added a RadCodeBlock around my javascript section and that seemed to fix it. 

    Thanks...  Jason
  6. SamVanity
    SamVanity avatar
    154 posts
    Member since:
    Apr 2006

    Posted 26 Apr 2007 Link to this post

    I am getting this error too. And I don't have code blocks at all. The following is the code:

    1                <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"
    2                    <asp:Label ID="noAvatarWarn" runat="server" /> 
    3                    <asp:Image ID="avatar" runat="server" /> 
    4                    <asp:Image ID="offlineAvatar" runat="server" /> 
    5                    <asp:Button ID="Button2" runat="server" Text="Button" SkinID="hiddenbutton" /> 
    6                </telerik:RadAjaxPanel> 

    by the way, I originally coded this part with RadAjaxPanel, and everything worked fine.
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 26 Apr 2007 Link to this post

    Hello Sam,

    Do you have "Theme" applied on your page - this may cause such exception. You can post the entire page declaration to give you more to-the-point explanation.

    Best regards,
    Vlad
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. SamVanity
    SamVanity avatar
    154 posts
    Member since:
    Apr 2006

    Posted 26 Apr 2007 Link to this post

    yes, I do have theme applied to the page. What should I watch out for?

    The page is in nested masterpages (2) as well. The only relevant thing is

    <asp:Button runat="server" CssClass="hiddenButtons" skinId="hiddenbutton" />

    as in the skin file. I don't apply skin to the telerik.radajaxpanel.

    The page is too huge to post on the forum.
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 Apr 2007 Link to this post

    Hi Sam,

    I tried to replicate this unfortunately to no avail - it seems that the source of the problem is somewhere else. You can find small demo attached.

    Sincerely yours,
    Vlad
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. SamVanity
    SamVanity avatar
    154 posts
    Member since:
    Apr 2006

    Posted 27 Apr 2007 Link to this post

    I do have a script block containing <%%> outside of the new RadAjaxPanel. do I have to enclose those in RadCodeBlock? They are not inside the AjaxPanel though.

    I did try enclosing the script block I have with RadCodeBlock but it still does not work (same error message).

    What about script blocks in the masterpage? Do I have to worry about those?
  11. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 27 Apr 2007 Link to this post

    Hello Sam Van,

    Yes, you must enclose those code blocks within telerik:RadCodeBlock tag. If that does not help, would you please isolate the issue as much as possible and send the code via support ticket?

    Thank you in advance for your cooperation.

    Kind regards,
    Konstantin Petkov
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  12. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 27 Apr 2007 Link to this post

    Konstantin-

    Can you take a moment and explain why RadCodeBlocks are necessary with the new "Prometheus" RadAjax? I don't think the documentation has much on these new controls yet and they seem to be a point of confusion.

    Thanks~
    Todd

  13. SamVanity
    SamVanity avatar
    154 posts
    Member since:
    Apr 2006

    Posted 27 Apr 2007 Link to this post

    exactly. We do need more information regarding this RadCodeBlock thing. There is not much about the use and reason for this in the document at all. And again, do I have to worry about those script blocks in the masterpage / user control ?
  14. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 30 Apr 2007 Link to this post

    Hi Sam, Todd,

    The way script blocks are implemented in ASP.NET may interfere with ajax manager's render interception mechanism. Тhat is why we have created the workaround of enclosing script blocks in a RadCodeBlock control. Moving scripts inside a RadCodeBlock control will isolate the effects to that control only and the partial rendering code will not be affected.

    Sam, please enclose all those scripts in RadCodeBlock even at your MasterPage/WebUserControl.

    Kind regards,
    Konstantin Petkov
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  15. Ken Fleming
    Ken Fleming avatar
    12 posts
    Member since:
    Apr 2007

    Posted 01 May 2007 Link to this post

    For what it's worth this error also happens if the "code block" is in a javascript on the page (e.g. ajaxRequest = <%=Radmanager.ClientID%>).
  16. Ronaldo
    Ronaldo avatar
    5 posts
    Member since:
    Oct 2007

    Posted 09 Oct 2007 Link to this post

    I'm so sorry but can you please show a sample syntax on how and where to put the "telerik:RadCodeBlock" tag?
    for example:
    window["<%= rgdContactPerson.ClientID %>"].AjaxRequest("<%= rgdContactPerson.UniqueID %>", "CloseForm");

    Thanks!
  17. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 10 Oct 2007 Link to this post

    Hello Ronaldo,

    Here is an example:

    <head runat="server"
        <telerik:RadCodeBlock runat="server"
            <script type="text/javascript"
                function MyFunction () 
                { 
                } 
            </script> 
        </telerik:RadCodeBlock> 
    </head> 

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  18. UT_DEV
    UT_DEV avatar
    20 posts
    Member since:
    Sep 2007

    Posted 28 Nov 2007 Link to this post

    So as I understand this block <telerik:RadCodeBlock runat="server">
    must be applied to any javascript that is dealing with telerik prometheus controls. Is it correct
  19. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 28 Nov 2007 Link to this post

    Hello Ilya,

    Yes, this information is correct. Generally speaking, you should wrap any client-side code which contains server tags in RadScriptBlock. Review paragraph 6 of this help article for more info.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  20. rh
    rh avatar
    193 posts
    Member since:
    Jan 2007

    Posted 03 Jan 2008 Link to this post

    I think requiring the RadCodeBlock is unacceptable. I've been trying to "upgrade" to Prometheus but am unable to because I have dozens and dozens of usercontrols and hundreds of pages and I can't go into every page and usercontrol and add this RadCodeBlock tag around any of my script that uses the <%= %> syntax.
  21. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 04 Jan 2008 Link to this post

    Hi rh,

    Unfortunately I have to agree with you -- this task is quite tedious in case of plenty of pages containing server code blocks. We will once again look into that and try to find another workaround.

    Please, excuse us for the inconvenience.

    Kind regards,
    Konstantin Petkov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  22. Ambu
    Ambu avatar
    18 posts
    Member since:
    Jan 2008

    Posted 05 Mar 2008 Link to this post

    I got my page to run by blocking out the javascript, but now the javascript seems to run after the AJAX runs. I did not have the problem with previous RadAjax. Please advise, this entire page may need to be recoded. 

    RadAjaxPanel1.ResponseScripts.Add(

    string.Format("hideDropDowns();"));


    function hideDropDowns()

    {

    var ddlIDs = document.getElementById('<%= dropDownListIDs.ClientID %>');

    var ids = ddlIDs.value.split(',');

    for( var i = 0 ; i < ids.length ; i++)

    {

    if( ids[i] != '')

    {

    try {

    var currentDropDown = document.getElementById(ids[i]);

    currentDropDown.style.display =

    "none";

    currentDropDown.style.visibility =

    "hidden";

    }

    catch(e) {};

    }

    }

    }

  23. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 06 Mar 2008 Link to this post

    Hi Allan,

    Can you elaborate on what do you mean by "I got my page to run by blocking out the javascript, but now the javascript seems to run after the AJAX runs"?

    All the best,
    Steve
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  24. Ambu
    Ambu avatar
    18 posts
    Member since:
    Jan 2008

    Posted 06 Mar 2008 Link to this post

    I blocked out the JavaScript using the RadCodeBlock tags. The page now loads with all the dropdowns visible and then quickly changes to hide them properly. This causes the page to load too wide and then fix itself. Before, the page would just load correctly from the start.


    <

    telerik:RadCodeBlock runat="server">

    <

    script language="javascript" type="text/javascript">

    <!--

    function displayDropDown(timeTypeDD, projectDD, sctsDD, otherDD)

    {

    var ddlIDs = document.getElementById('<%# dropDownListIDs.ClientID %>');

    var selectedValue = timeTypeDD.value;

    if (selectedValue == 1) {

    projectDD.style.display =

    "inline";

    projectDD.style.visibility =

    "visible";

    projectDD.focus();

    sctsDD.style.display =

    "none";

    sctsDD.style.visibility =

    "hidden";

    otherDD.style.display =

    "none";

    otherDD.style.visibility =

    "hidden";

    }

    else if (selectedValue == 2) {

    projectDD.style.display =

    "none";

    projectDD.style.visibility =

    "hidden";

    sctsDD.style.display =

    "inline";

    sctsDD.style.visibility =

    "visible";

    sctsDD.focus();

    otherDD.style.display =

    "none";

    otherDD.style.visibility =

    "hidden";

    }

    else if (selectedValue == 3) {

    projectDD.style.display =

    "none";

    projectDD.style.visibility =

    "hidden";

    sctsDD.style.display =

    "none";

    sctsDD.style.visibility =

    "hidden";

    otherDD.style.display =

    "inline";

    otherDD.style.visibility =

    "visible";

    otherDD.focus();

    }

    }

    function hideDropDowns()

    {

    var ddlIDs = document.getElementById('<%= dropDownListIDs.ClientID %>');

    var ids = ddlIDs.value.split(',');

    for( var i = 0 ; i < ids.length ; i++)

    {

    if( ids[i] != '')

    {

    try {

    var currentDropDown = document.getElementById(ids[i]);

    currentDropDown.style.display =

    "none";

    currentDropDown.style.visibility =

    "hidden";

    }

    catch(e) {};

    }

    }

    }

    function focusCategory(categoryDD)

    {

    categoryDD.focus();

    }

    -->

    </

    script>

    </

    telerik:RadCodeBlock>


  25. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 06 Mar 2008 Link to this post

    Hi Allan,

    Unfortunately I was not able to reproduce your problem. I am attaching a sample project illustrating my approach to this forum post. Please tell us if we omitted something from your logic - this can lead us to the source of the issue to eliminate it accordingly.

    Kind regards,
    Iana
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  26. Ambu
    Ambu avatar
    18 posts
    Member since:
    Jan 2008

    Posted 06 Mar 2008 Link to this post

    deleted post
  27. Ambu
    Ambu avatar
    18 posts
    Member since:
    Jan 2008

    Posted 06 Mar 2008 Link to this post

    deleted post
  28. Ambu
    Ambu avatar
    18 posts
    Member since:
    Jan 2008

    Posted 06 Mar 2008 Link to this post

    Iana,

    I will build a demo app and create a new support ticket.

    Thanks,
    Allan
  29. bradhh
    bradhh avatar
    25 posts
    Member since:
    Feb 2007

    Posted 30 Apr 2008 Link to this post

    I am in the correct thread, just wanted to mention that since the red WARNING pops up here.

    ASP.NET AJAX (formerly "Prometheus") is causing me problems. My site worked fine before I upgraded, but now some pages seem unable to load because of the error noted in this thread. Not all of my pages, but most of them. Some pages that have the RadAjaxManager seem to work fine, but others do not. Here is the call stack associated with this 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) +2108046  
       Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) +171  
       Telerik.Web.UI.RadAjaxControl.PerformRender() +373  
       Telerik.Web.UI.RadAjaxControl.OnPageRender(HtmlTextWriter writer, Control page) +1309  
       Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) +152  
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +98  
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20  
       System.Web.UI.Page.Render(HtmlTextWriter writer) +26  
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121  
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22  
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558 

    I find that the "workaround" you posted concerning the RadCodeBlock tag fixes my problem. This is completely unacceptable, as noted by Konstantin Petkov in the post of 1/4/2008 1:31:07 AM below. Konstantin acknowledged the unacceptable nature of this solution in early January, nearly four months ago, and still no solution has been found. This, also, is unacceptable.

    I'm finding that my code works fine if I delete RadAjaxManager from the page. That seems like an odd solution for a set of controls that has AJAX in the name.

    Should I just go back to the old version of the controls? Why then did I pay the subscription price?
  30. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 01 May 2008 Link to this post

    Hi Brad,

    Many of the controls no longer allow server code blocks (like window["<%=RadGrid1.ClientID%>"]) inside scripts residing in page head tag -- from now on they register their CSS files into page header. You need to either wrap the script inside additional PlaceHolder or move it into the page body instead. Nevertheless, I have passed your comments to our developers, for further consideration. Any additional details as to why you find the use of RadCodeBlock unacceptable would be appreciated.

    Regards,
    Yavor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  31. bradhh
    bradhh avatar
    25 posts
    Member since:
    Feb 2007

    Posted 01 May 2008 Link to this post

    I was very frustrated yesterday. Today I'm feeling much better, but I have to admit I haven't started working yet.  :)  Still, sorry about yesterday's rant.

    However, I still have some issues with this whole situation. Asking us to move <script> blocks out of the <head> is not an acceptable solution. <script> blocks belong in the <head>, that's how HTML is set up.

    Telling us we can't use code blocks (<%  %>) in our scripts is not acceptable either. You're saying that your ASP.NET AJAX controls don't support ASP.NET. If that's the case, then you really can't call them ASP.NET controls, can you?

    Also, every example of the RadAjaxLoadingPanel I've seen on your site uses code blocks (<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>). If the RadAjaxManager is having trouble with code blocks, why is your RadAjaxLoadingPanel using them? All of your other controls seem to be able to find their images in the Telerik.dll file without using code blocks. Why does the RadAjaxLoadingPanel seem to be unable to do this? And do I need to wrap that code block in <RadCodeBlock> tags?

    At this point I can get by with the <RadCodeBlock> tags in my code. I don't use many code blocks, since I try to follow the ASP.NET programming model of separating UI from business logic. Still, ASP.NET code blocks are an integral part of ASP.NET programming, as Telerik has demonstrated in the use of them in the RadAjaxLoadingPanel. I do hope that this issue gets resolved soon.

    Thanks -
    Brad
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017