I have an ASP.net control that inherits from UserControl
:
File 1:
public partial class Controls_AllocationDuplicate : System.Web.UI.UserControl
File 2:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AllocationDuplicate.ascx.cs" Inherits="Controls_AllocationDuplicate" %>
I need the control to inherit from Control
, rather than UserControl
:
File.aspx.cs (changed):
public partial class Controls_AllocationDuplicate : System.Web.UI.Control
File.aspx (not changed):
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AllocationDuplicate.ascx.cs" Inherits="Controls_AllocationDuplicate" %>
When i do this, Visual Studio gives a compile error:
Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
How can I have my control inherit from Control
rather than UserControl
?
Series
This question is one in the ongoing Stackoverflow series, "Templating user controls":
You try to make a custom control and not a user control in this case you can't use ascx file to hold your design but need to design them pragmatically.
Try inherting from WebControl,then use Register instead of Control. Similar to this: http://www.codeproject.com/Articles/2748/Building-an-ASP-NET-custom-web-control-a-textbox-a