title: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)
body: <p>I have a web user control:</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="SitewideNotification.ascx.cs" Inherits="Controls_Fresh_SitewideNotification" %&gt;
  
  &lt;asp:PlaceHolder runat="server" ID="Javascript"&gt;
      test
  &lt;/asp:PlaceHolder&gt;
  </code></pre>
  
  <p>In my code behind I have:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      Page.Master.FindControl("JSContent").Controls.Add(Javascript);
  }
  </code></pre>
  
  <p>My master page ends with:</p>
  
  <pre><code>        &lt;asp:ContentPlaceHolder runat="server" ID="JSContent"/&gt;
  
      &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But I get the error:</p>
  
  <pre><code>System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. &lt;% ... %&gt;).
  
  Page.Master.FindControl("JSContent").Controls.Add(Javascript);
  </code></pre>
  
  <p>I'm a bit lost as to why this is, does anyone know how to fix it?</p>