如何继承的控制,而不是用户控件? [英] How to inherit from Control, rather than UserControl?
问题描述
我有一个继承自一个ASP.net控制用户控件
:
文件1
公共部分类Controls_AllocationDuplicate:System.Web.UI.UserControl
文件2
<%@控制语言=C#AutoEventWireup =真codeFILE =AllocationDuplicate.ascx.cs继承=Controls_AllocationDuplicate%GT;
File.aspx.cs (改变)的:
公共部分类Controls_AllocationDuplicate:System.Web.UI.Control
File.aspx (没有变化)的:
<%@控制语言=C#AutoEventWireup =真codeFILE =AllocationDuplicate.ascx.cs继承=Controls_AllocationDuplicate%GT;
当我这样做时,Visual Studio提供了一个编译错误:
确认,在此code文件中定义的类继承属性匹配,并且它的扩展正确的基类(例如Page或UserControl)。
块引用>我怎么有我的控制的从
控制
,而不是用户控件
?<继承/ p>系列
这个问题是一个在正在进行的系列#1,模板的用户控件
- How一个模板添加到用户控件?
- How从控制继承,而不是用户控件?
- UserControl拥有的IsPostBack,但控制不
- UserControl不具有公共属性命名的ContentTemplate
- How我该从web.config中指定codeFileBaseClass?
解决方案您尝试进行自定义的控制,而不是在这种情况下,你不能使用的ascx文件来保存你的设计,但需要以务实的态度设计它们的用户控件。
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 thanUserControl
: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 do i have my control inherit from
Control
rather thanUserControl
?Series
This question is one in the ongoing Stackoverflow series, "Templating user controls":
- How to add a Templating to a UserControl?
- How to inherit from Control, rather than UserControl?
- UserControl has IsPostBack, but Control does not
- UserControl does not have public property named ContentTemplate
- How do i specify CodeFileBaseClass from web.config?
解决方案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.
这篇关于如何继承的控制,而不是用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!