0

I am using a page based on the 'Redirect Page Layout'.

I can create the page, set the page-layout, and even specify the redirect url. I can check-in the page with no problems. However, as soon as I click 'Publish' I get an error saying:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

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

Source Error: 


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 



[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +11048618
Microsoft.SharePoint.Publishing.WebControls.RedirectControl.CreateChildControls() +309
System.Web.UI.Control.EnsureChildControls() +146
System.Web.UI.Control.PreRenderRecursiveInternal() +61
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224 
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Control.PreRenderRecursiveInternal() +224
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394

I do have a custom master page running, but I can select other page layouts (ie. Body, article-page, etc.) with no problems.

Any ideas?

EDIT:

Appears as though there was one code block in particular that was causing the issue in the :

<%if (LCID == 1036)
  { %>
    <link href="../_layouts/STYLES/master_SJA/masterMainFR.css" rel="stylesheet" type="text/css" />
    <!--[if IE 9]>
        <link href="../_layouts/STYLES/master_SJA/ie9stylesFR.css" rel="stylesheet" type="text/css" />    
    <![endif]-->
    <!--[if IE 8]>
        <link href="../_layouts/STYLES/master_SJA/ie8stylesFR.css" rel="stylesheet" type="text/css" />    
    <![endif]-->
    <!--[if IE 7]>
        <link href="../_layouts/STYLES/master_SJA/ie7stylesFR.css" rel="stylesheet" type="text/css" />    
    <![endif]-->
<% } %>

I placed this code block in a asp:ContentPlaceHolder and no longer received the error.

1

the registering of code block is being rendered as a comment block,

look in your custom code for <%= and do the following to it:

change <%= to <%# should do the trick!

so if you had:

<a src="<%= ResolveUrl("/_Layouts/1033/helloPage.aspx") %>"> hello world </a>

change it too:

<a src="<%# ResolveUrl("/_Layouts/1033/helloPage.aspx") %>"> hello world </a>

EDIT

lol now you have mentioned masterpage i now know what your trying todo ;) , its auto that its rejected within a masterpage!

so follow this guide!

1) revert the changes that i suggested above so it is back to how it was!

2) goto the web applications web.config file to ammend, the file would be located here:

C:\inetpub\wwwroot\wss\VirtualDirectories\YourWebAppDirectory

3) once you have opened the config file goto:

  <PageParserPaths>

and change AllowServerSideScript to true:

    <PageParserPath VirtualPath="/_catalogs/masterpage/MetroUI8.aspx" CompilationMode="Always" AllowServerSideScript="true" />

so it was:

  <PageParserPaths>
    <PageParserPath VirtualPath="/_catalogs/masterpage/masterpage.master" CompilationMode="Always" AllowServerSideScript="false" />
  </PageParserPaths>

now its:

  <PageParserPaths>
    <PageParserPath VirtualPath="/_catalogs/masterpage/masterpage.master" CompilationMode="Always" AllowServerSideScript="true" />
  </PageParserPaths>

4) save file, exit and reload the page and it should work fine ;)

this can also work on layouts page if you have code within layouts file (aspx) just change the file name and extension ;)

EDIT 2

stylsheet based on branding for selected browsers, for me i find it much easier to maintain if its all in one style sheet. Less files!

this way you only load one style sheet within the masterpage and within the css you use the following:

either use prefix (one class many browsers)

•-ms- Microsoft
•mso- Microsoft Office
•-moz- Mozilla Foundation (Gecko-based browsers)
•-o-, -xv- Opera Software
•-atsc- Advanced Television Standards Committee
•-wap- The WAP Forum
•-webkit- Safari, Chrome (and other WebKit-based browsers)
•-khtml- Konqueror browser
•-apple- Webkit supports properties using the -apple- prefixes as well
•prince- YesLogic
•-ah- Antenna House
•-hp- Hewlett Packard
•-ro- Real Objects
•-rim- Research In Motion
•-tc- Tall Components

https://stackoverflow.com/questions/5411026/list-of-css-vendor-prefixes

http://peter.sh/experiments/vendor-prefixed-css-property-overview/

.someclass
{
  //mozilla
  -moz-border-radius: 10px 5px;
  //most other browsers
  -webkit-border-top-left-radius: 10px;
  -webkit-border-top-right-radius: 5px;
  -webkit-border-bottom-right-radius: 10px;
  -webkit-border-bottom-left-radius: 5px;
  //ie css 3.0
  border-radius: 10px 5px; 
}

above is just an example of how to make rounded corners.

another example:

.class
{
    //most browsers
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#f7f7f7);
    //ie browsers 
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffff, endColorstr=#f7f7f7)"; 
}

http://webdesign.about.com/od/css/a/css-vendor-prefixes.htm

  • All of my code blocks in my custom master page use <%# instead of <%=, and I still get the error. – TeddyRuxpin Oct 17 '13 at 13:39
  • just ammended my answer – Ali Jafer Oct 17 '13 at 14:12
  • I followed the steps, and I still get the error. I tried using the v4.master and it worked, so it must be something in my master – TeddyRuxpin Oct 17 '13 at 15:09
  • 1
    try posting some code so i know where your going wrong? – Ali Jafer Oct 17 '13 at 15:29
  • I updated the question. Thanks for all your help. Is there a better way to load conditional stylesheets by language? – TeddyRuxpin Oct 17 '13 at 16:03
0

The offending code block was an if statement on the master page in the section. I placed the code into an 'asp:ContentPlaceHolder' block and that fixed the problem.

  • ahh yes, your right ;), your not allowed any code out of any placeholder! hence why it was failing at <%if, having what i put below plus what you did(having code within placeholder) obviously worked! you got there before i could :( lol. – Ali Jafer Oct 18 '13 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.