如何继承的控制,而不是用户控件? [英] How to inherit from Control, rather than UserControl?

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

问题描述

我有一个继承自一个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,模板的用户控件


解决方案

您尝试进行自定义的控制,而不是在这种情况下,你不能使用的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 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 do 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.

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

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