title: How to inherit from Control, rather than UserControl?
body: <p>I have an ASP.net control that inherits from <code>UserControl</code>:</p>
  
  <p><strong>File 1</strong>:</p>
  
  <pre><code>public partial class Controls_AllocationDuplicate : System.Web.UI.UserControl
  </code></pre>
  
  <p><strong>File 2</strong>:</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="AllocationDuplicate.ascx.cs" Inherits="Controls_AllocationDuplicate" %&gt;
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/11658053/how-to-add-a-templating-to-a-usercontrol">I need the control to inherit from <code>Control</code>, rather than <code>UserControl</code></a>:</p>
  
  <p><strong>File.aspx.cs</strong> <em>(changed)</em>:</p>
  
  <pre><code>public partial class Controls_AllocationDuplicate : System.Web.UI.Control
  </code></pre>
  
  <p><strong>File.aspx</strong> <em>(not changed)</em>:</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="AllocationDuplicate.ascx.cs" Inherits="Controls_AllocationDuplicate" %&gt;
  </code></pre>
  
  <p>When i do this, Visual Studio gives a compile error:</p>
  
  <blockquote>
    <p>Make sure that the class defined in this code file matches the 'inherits' attribute, and that it <strong>extends the correct base class (e.g. Page or UserControl).</strong></p>
  </blockquote>
  
  <p>How can I have my <em>control</em> inherit from <code>Control</code> rather than <code>UserControl</code>?</p>
  
  <h2>Series</h2>
  
  <p>This question is one in the ongoing Stackoverflow series, <strong>"Templating user controls"</strong>:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/11658053/how-to-add-a-templating-to-a-usercontrol/11700540">How to add a Templating to a UserControl?</a></li>
  <li><a href="https://stackoverflow.com/questions/12323303/how-to-inherit-from-control-rather-than-usercontrol">How to inherit from Control, rather than UserControl?</a></li>
  <li><a href="https://stackoverflow.com/questions/12321621/usercontrol-has-ispostback-but-control-does-not/12321692">UserControl has IsPostBack, but Control does not</a></li>
  <li><a href="https://stackoverflow.com/questions/11656637/usercontrol-does-not-have-public-property-named-contenttemplate">UserControl does not have public property named ContentTemplate</a></li>
  <li><a href="https://stackoverflow.com/questions/12325192/how-do-i-specify-codefilebaseclass-from-web-config">How do i specify CodeFileBaseClass from web.config?</a></li>
  </ul>