加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何从Control继承而不是UserControl?

发布时间:2020-12-16 09:48:02 所属栏目:asp.Net 来源:网络整理
导读:我有一个继承自UserControl的ASP.net控件: 档案1: public partial class Controls_AllocationDuplicate : System.Web.UI.UserControl 文件2: %@ Control Language="C#" AutoEventWireup="true" CodeFile="AllocationDuplicate.ascx.cs" Inherits="Control
我有一个继承自UserControl的ASP.net控件:

档案1:

public partial class Controls_AllocationDuplicate : System.Web.UI.UserControl

文件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(已更改):

public partial class Controls_AllocationDuplicate : System.Web.UI.Control

File.aspx(未更改):

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AllocationDuplicate.ascx.cs" Inherits="Controls_AllocationDuplicate" %>

当我这样做时,Visual Studio给出一个编译错误:

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).

如何让我的控件继承自Control而不是UserControl?

系列

这个问题是正在进行的Stackoverflow系列中的一个,“模板化用户控件”:

> 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?

解决方法

尝试从WebControl中继承,然后使用Register而不是Control.
与此类似: http://www.codeproject.com/Articles/2748/Building-an-ASP-NET-custom-web-control-a-textbox-a

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读