How to inherit from Control, rather than UserControl?(如何从 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).
我怎样才能让我的 control 从 Control
而不是 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":
- 如何向用户控件添加模板?一个>
- 如何继承自Control,而不是继承自UserControl?
- UserControl 有 IsPostBack,但 Control 没有
- UserControl 没有名为 ContentTemplate 的公共属性
- 如何从 web.config 指定 CodeFileBaseClass?
推荐答案
您尝试制作自定义控件而不是用户控件,在这种情况下您不能使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 Control 继承,而不是 UserControl?
基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01