title: How to create a custom control with INamingContainer?
body: <p>I am trying the following:</p>
  
  <pre><code>[PersistenceMode(PersistenceMode.InnerProperty)]
  [TemplateContainer(typeof(TemplateContainer))]
  public virtual ITemplate LayoutTemplate { get; set; }
  
  protected void Page_Init(object sender, EventArgs e)
  {
      this.Controls.Clear();
  
      if (LayoutTemplate != null)
      {
          var data = Enumerable.Range(0, 10);
  
          foreach (int index in data)
          {
              TemplateContainer container = new TemplateContainer(index);
  
              LayoutTemplate.InstantiateIn(container);
  
              this.Controls.Add(container);
          }
      }
  }
  </code></pre>
  
  <p>My container class:</p>
  
  <pre><code>public class TemplateContainer : Control, INamingContainer
  {
      public int Index { get; set; }
  
      internal TemplateContainer(int index)
      {
          this.Index = index;
      }
  }
  </code></pre>
  
  <p>And my markup:</p>
  
  <pre><code>&lt;uc:TemplateControl ID="ucTemplateControl" runat="server"&gt;
      &lt;LayoutTemplate&gt;
          &lt;b&gt;Index:&lt;/b&gt;
          &lt;asp:TextBox ID="Literal1" runat="server"
              Text='&lt;%# Container.Index %&gt;'
              ReadOnly="true" /&gt;
          &lt;br /&gt;
      &lt;/LayoutTemplate&gt;
  &lt;/uc:TemplateControl&gt;
  </code></pre>
  
  <p>But for some reason <code>Container.Index</code> is not rendering any value, just empty. 10 controls are being created, but none shows a value.</p>
  
  <p>What did I do wrong? How can I fix it so it will show the <code>Index</code> value?</p>
  
  <p>I tried something similar to MSDN example:</p>
  
  <ul>
  <li><a href="http://msdn.microsoft.com/en-us/library/36574bf6%28v=vs.100%29.aspx" rel="nofollow">How to: Create Templated ASP.NET User Controls</a></li>
  </ul>