如何从 Control 继承,而不是 UserControl? [英] How to inherit from Control, rather than UserControl?

查看:28
本文介绍了如何从 Control 继承,而不是 UserControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个继承自 UserControl 的 ASP.net 控件:

I have an ASP.net control that inherits from UserControl:

文件 1:

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

文件 2:

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

我需要控件从 Control,而不是 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 会给出一个编译错误:

When i do this, Visual Studio gives a compile error:

确保此代码文件中定义的类与继承"属性匹配,并且它扩展了正确的基类(例如 Page 或 UserControl).

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

我怎样才能让我的 controlControl 而不是 UserControl 继承?

How can I have my control inherit from Control rather than UserControl?

这个问题是 Stackoverflow 系列中的一个,模板化用户控件":

This question is one in the ongoing Stackoverflow series, "Templating user controls":

推荐答案

您尝试制作自定义控件而不是用户控件,在这种情况下您不能使用 ascx 文件来保存您的设计,但需要务实地设计它们.

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.

这篇关于如何从 Control 继承,而不是 UserControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆