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
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,
the Telerik team
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?
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
Thank you for your reply. I figured out my problem just a few minutes ago. I removed the "~/" from my code and it worked.
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
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