05/15/2008 18:56:14.90 w3wp.exe (0x1554) 0x06B8 Windows SharePoint Services General 8nca Verbose Application error when access /schools/test0001/Pages/default.aspx, Error=The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). at System.Web.UI.ControlCollection.Add(Control child) at Telerik.RadEditorUtils.RadControl.RegisterCssFile(String path) at Telerik.RadEditorUtils.RadControl.RenderRuntimeSkin() at Telerik.RadEditorUtils.RadControl.Page_PreRenderComplete(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Web.UI.Page.OnPreRenderComplete(EventArgs e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
The layout page and web.config files are identical on both sites. any help is appreciated.
I have found several posts that state that you cannot have <%%> in the <head> tag. The question is why does it work sometimes and not work others. I do have <%%> in the <head> but I cannot get rid of them.
Thanks,
Bill
10 Answers, 1 is accepted
Indeed, this problem is observed when there is a script block in the HEAD tag. To solve the problem, you should remove the script block from the head tags and put it somewhere else (e.g. put it in the body). Also please check the head for runat="server" attribute and if it is present please remove it.
The following Google search lists a lot of forum discussions on this topic on various ASP.NET community sites:
http://www.google.com/search?hl=en&q=The+Controls+collection+cannot+be+modified+because+the+control+contains+code+blocks+%28i.e.+%3C%25+...+%25%3E%29
I hope this helps.
Kind regards,
George
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thank you for the feedback, but unfortunately I cannot remove either the "runat" or the <%%> from the head. I have information that needs to be populated there. The real question is why does this only fail some of the time? Meaning, why does this problem not manifest itself in my development box, but only seems to be happening on production. Is there a fix coming for this? Have you identified to code that fails? Is it yours or is it SharePoint itself?
Thanks again,
Bill Safcik
You can set the server tags within RadCodeBlock. Fore more information please review the following article:
http://www.telerik.com/help/aspnet-ajax/ajxradscriptblockradcodeblock.html
I hope this helps.
Sincerely,
George
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Do you have any other suggestions?
Could you please open a support ticket and send me the problematic ASPX page. I will check it and do my best to provide a solution.
Note that, the RadCodeBlock should be used when you have server code blocks placed within the markup (most often some JavaScript functions accessing server controls) and it prevents the server error:
System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
For example:
<head> |
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> |
<script language="javascript" type="text/javascript"> |
function AjaxReq(args) |
{ |
$find("<%= RadAjaxPanel1.ClientID %>").ajaxRequestWithTarget("<%= Button1.UniqueID %>", ''); |
} |
</script> |
</telerik:RadCodeBlock> |
</head> |
Looking forward to hearing from you,
George
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Frank
Could you provide us with source code of you page? Also inform us which version of RadEditor for MOSS you are using.
Thank you.
Kind regards,
Stanimir
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The code that I need to run is:
<%
SPWeb myWeb = SPControl.GetContextWeb(Context);
SPUser uCurrent = myWeb.CurrentUser;
String domain = "gpnet";
String SiteName = myWeb.Url;
String CurrentPage = HttpContext.Current.Request.Url.AbsoluteUri.ToString().ToLower().Trim();
CurrentPage = CurrentPage.Substring(CurrentPage.LastIndexOf("/")+1);
Page.Title = CurrentPage + " - " + SiteTitle;
//Check for Cookie existence
if (Request.Cookies["TermsOfUse"]==null)
{
//Redirect to terms page.
Response.Redirect(SiteName + "/_layouts/GP_Custom/termsofuse/terms.aspx?OrigUrl="+ Server.UrlEncode(SiteName), true);
//Response.Redirect("/_layouts/GP_Custom/keepalive.aspx", true);
}
%>
Thanks
Frank
If the code that you need to run is in the head tag, you should make sure that there is no runat="server" attribute in it.
I hope this helps.
All the best,
Stanimir
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Even when the "Head" has the attribute runat="server", I have no problems.
Example, just placed this in my PageLayout.
<head id="Head1" runat="server">
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<style type="text/css">
.homepageBanner
{
background-image: url('/Style%20Library/Parentix/img/homeimage<%Random random = new Random(); System.Web.HttpContext.Current.Response.Write(random.Next(1, 5));%>.png');
background-repeat: no-repeat;
height: 237px;
width: 948px;
}
</style>
</telerik:RadCodeBlock>
</head>
Works fine!