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

8 posts, 0 answers
  1. Jon
    Jon avatar
    22 posts
    Member since:
    Oct 2010

    Posted 08 Nov 2010 Link to this post

    This problem vexxed me for a short while, because the message returned is pretty generic and the stack trace didn't really hep me pinpoint the issue.

    I eventually isolated this (I thought) to a RadAjaxPanel control I had declared:

    <telerik:RadAjaxPanel ID="radPanel" runat="server" HorizontalAlign="NotSet" 
        LoadingPanelID="radLoadingPanel">
            <asp:DropDownList ID="ddlTierID" runat="server" DataSourceID="BusinessUnitTypesDataSource"
                DataTextField="Name" DataValueField="RowID" TabIndex="7">
            </asp:DropDownList>
    </telerik:RadAjaxPanel>

    If I replaced this code block with the Microsoft flavor (which is what I'd tried to convert over to Telerik) like this:

    <asp:UpdatePanel UpdateMode="Conditional" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlUserRole" EventName="SelectedIndexChanged" />
        </Triggers>
        <ContentTemplate>
            <asp:DropDownList ID="ddlTierID" runat="server" DataSourceID="BusinessUnitTypesDataSource"
                DataTextField="Name" DataValueField="RowID" TabIndex="7">
            </asp:DropDownList>
        </ContentTemplate>
    </asp:UpdatePanel>

    then the page runs fine. However, I didn't understand why the Telerik panel should cause an issue, until I found this article:

    http://www.telerik.com/help/aspnet-ajax/troubleshooting.html

    At the top of the page containing the panel, I had this seemingly innocuous JavaScript snippet that simply set the focus to the first field on the form:

    <script type="text/javascript">
        function pageLoad()
        {
            $get('<%=txtUserName.ClientID %>').focus();
        }
    </script>

    Based on the Telerik article, above, I wrapped this snippet in a RadCodeBlock and then the RadAjaxPanel code worked fine!

    Hope this helps someone else!

    Jon
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 09 Nov 2010 Link to this post

    Hi Jon,

    RadCodeBlock should be used when you have server code blocks placed within the markup (most often some JavaScript functions accessing server controls). Indeed RadCodeBlock prevents the server error:

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

    More information about when you should use RadCodeBlock and RadScriptBlock is available in this help article.

    All the best,

    Pavlina
    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jason
    Jason avatar
    2 posts
    Member since:
    Dec 2012

    Posted 26 Feb 2013 Link to this post

    I am getting the same erro message when I try and run JQuery from my server. I don't have a problem running the Telerik controls locally, but I publish my project to the server it will not runn my JQuery.  I found a solution and here it is.
    This code is the only way to get JQuery to work on the Server:(Now all of our sites are running as applications of the Default Web Site)
    <script src="<% = ResolveUrl("~/Scripts/jquery-1.4.1.min.js") %" type="text/javascript"></script>
    <script src="<% = ResolveUrl("~/Scripts/jquery-1.4.1.js") %"></script>
    ect.

    This code works fine locally:
    <script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="/Scripts/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.idletimer.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.idletimeout.js" type="text/javascript"></script>
    Can Anyone Help Me?
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 28 Feb 2013 Link to this post

    Hello Jason,

    Try to wrap your JavaScript code in RadScriptBlock and see if it helps:
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
    <script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="/Scripts/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.idletimer.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.idletimeout.js" type="text/javascript"></script>
    </telerik:RadScriptBlock>

    Regards,
    Pavlina
    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.
  6. Jason
    Jason avatar
    2 posts
    Member since:
    Dec 2012

    Posted 28 Feb 2013 Link to this post

    Ron,

    Thank you for your reply.  I figured out my problem just a few minutes ago. I removed the "~/" from my code and it worked.
  7. Dirk
    Dirk avatar
    1 posts
    Member since:
    Aug 2013

    Posted 17 Sep 2015 in reply to Jon Link to this post

    Jon! I want to buy you a beer my man! Spot on!!! Thanks!
  8. Ravi
    Ravi avatar
    3 posts
    Member since:
    Mar 2011

    Posted 17 Mar in reply to Pavlina Link to this post

    If I have code block like this it brings blank background URL

    <label for="toggleboxteamview" id="navtogglermain" style="background: url('<%= ResolveUrl("~/images/viewhierarchy.gif")%>');"></label>

    If I use following code block

    <label for="toggleboxteamview" id="navtogglermain" style="background: url('<%# ResolveUrl("~/images/viewhierarchy.gif")%>');"></label>

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

    Any idea how to fix this?

    Regards,
    Ravi

  9. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 17 Mar Link to this post

    Hello Ravi,

    I have replied to your support ticket on the same matter and I am pasting my response here for anyone else having the same question:

    You need to wrap the server code block in a RadCodeBlock tag, as explained in the documentation: http://docs.telerik.com/devtools/aspnet-ajax/controls/ajaxmanager/radcodeblock-and-radscriptblock.

    For example:

    <telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
        <label for="toggleboxteamview" id="navtogglermain" style="background: url('<%= ResolveUrl("~/images/viewhierarchy.gif")%>');">
        </label>
    </telerik:RadCodeBlock>



    Regards,
    Marin Bratanov
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017