gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:02:48 26 4
gpt4 key购买 nike

我有一个继承自 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 :

文件.aspx.cs (更改):
public partial class Controls_AllocationDuplicate : System.Web.UI.Control

文件.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

    关于asp.net - 如何从 Control 而不是 UserControl 继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12323303/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com