title: ASP.NET: User control with access to the controls that it wraps
body: <p>I have a bunch of occurrences of this kind of boilerplate code in my ASP.NET project.</p>
  
  <pre><code>&lt;div class="inputfield"&gt;
    &lt;div class="tl"&gt;
      &lt;span class="tr"&gt;&lt;!-- --&gt;&lt;/span&gt;
      &lt;span class="ll"&gt;&lt;!-- --&gt;&lt;/span&gt;
      &lt;div class="lr"&gt;
        &lt;div class="cntnt"&gt;
          &lt;asp:TextBox .../&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>As you may have guessed, everything in that snippet is pure boilerplate except for the innermost text field.</p>
  
  <p>What is the best way to avoid such boilerplate in ASP.NET?  In e.g. Django I would make a custom tag for it, as such:</p>
  
  <pre><code>{% boiler %}
  &lt;input ... /&gt;
  {% endboiler %}
  </code></pre>
  
  <p>I was thinking that maybe I can create a user control, but all the tutorials on ASP.NET user controls that I've found are very simplistic and "self-closing", i.e. they are not aware of the contents of the tag.  I need something along the lines of:</p>
  
  <pre><code>&lt;Hello:MyControl&gt;
    &lt;asp:TextBox .../&gt;
  &lt;/Hello&gt;
  </code></pre>
  
  <p>So my question is the following: what's the best way to avoid the boilerplate?</p>