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

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

7 Answers 665 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 08 Nov 2010, 05:16 PM
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

7 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 09 Nov 2010, 11:20 AM
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
0
Jason
Top achievements
Rank 1
answered on 26 Feb 2013, 04:25 PM
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?
0
Pavlina
Telerik team
answered on 28 Feb 2013, 04:28 PM
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.
0
Jason
Top achievements
Rank 1
answered on 28 Feb 2013, 04:31 PM
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.
0
Dirk
Top achievements
Rank 1
answered on 17 Sep 2015, 09:45 AM
Jon! I want to buy you a beer my man! Spot on!!! Thanks!
0
Ravi
Top achievements
Rank 1
answered on 17 Mar 2016, 11:39 AM

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

0
Marin Bratanov
Telerik team
answered on 17 Mar 2016, 01:14 PM

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.
Tags
Ajax
Asked by
Jon
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Jason
Top achievements
Rank 1
Dirk
Top achievements
Rank 1
Ravi
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or