title: Custom Templated WebControls - Inner Contols are always null
body: <p>I'm building a templated web control for an asp .net web forms application. Most of it runs fine, but one problem I’m stuck with is that all the controls inside my template are null at runtime.</p>
  
  <p>For instance if my control is marked up like this:</p>
  
  <pre><code>&lt;fscc:CollapsiblePanel runat="server" ID="cpExample1" ImageControlId="image1" CssClass="curved"&gt;
      &lt;Header&gt;
          this is my header
          &lt;asp:Image ImageUrl="imageurl" runat="server" ID="image1" /&gt;
      &lt;/Header&gt;
      &lt;Body&gt;
          this is the body
      &lt;/Body&gt;
  &lt;/fscc:CollapsiblePanel&gt;
  </code></pre>
  
  <p>And my page load is like this:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      image1.ImageUrl = Paths.Images.expand_jpg;
  }
  </code></pre>
  
  <p>It will compile and run, but image1 is always null.</p>
  
  <p>I have added these attributes to the class: </p>
  
  <pre><code>[ParseChildren(true), PersistChildren(false)]
  public class MyControl : WebControl
  </code></pre>
  
  <p>And to the template property I have added these:</p>
  
  <pre><code>[Browsable(false),
   PersistenceMode(PersistenceMode.InnerProperty),
   TemplateInstance(TemplateInstance.Single)]
  public virtual ITemplate Header { get; set; }
  </code></pre>
  
  <p>So far as I can tell this is enough for the image1 control to be available. Also the tooling seems to recognise control and puts the image1 into the .designer.cs file, but it is always null. What am I missing?</p>