C# 我的控件“这里不允许,因为它不扩展类'System.Web.UI.UserControl'”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1665521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
My control is "not allowed here because it does not extend class 'System.Web.UI.UserControl'"
提问by Iain Fraser
So I have another noodle-scratcher (for me anyway).
所以我有另一个面条抓手(无论如何对我来说)。
I'm trying to create my own custom control in a CMS I only have partial source code for (i.e. samples the vendor has supplied to me). Basically I have created a class called DataDefinitionContent
which extends ControlBase
. Now, from what I can garner from the metadata, ControlBase
extends UserControl
, so I would have thought this would run without a drama. Can anyone shed any light on why this might not be working for me?
我正在尝试在 CMS 中创建我自己的自定义控件,我只有部分源代码(即供应商提供给我的示例)。基本上我创建了一个名为DataDefinitionContent
它 extends的类ControlBase
。现在,从我可以从元数据中获得的,ControlBase
extends UserControl
,所以我原以为这会在没有戏剧性的情况下运行。谁能解释为什么这可能对我不起作用?
My Class:
我的课:
public partial class DataDefinitionContent : ControlBase, ICustomControl<DataDefinition>
{
... Stuff
}
ControlBase:
控制库:
using System;
using System.Web.UI;
namespace CMS.Web
{
public class ControlBase : UserControl
{
... Stuff
}
}
My ascx file:
我的 ascx 文件:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DataDefinitionContent.ascx.cs"
Inherits="CMS.Admin.WebUI.CustomControls.DataDefinitionContent, CoA.Admin.WebUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" %>
The error I'm getting:
我得到的错误:
Parser Error Message: 'CMS.Admin.WebUI.CustomControls.DataDefinitionContent, CoA.Admin.WebUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not allowed here because it does not extend class 'System.Web.UI.UserControl'.
Line 1: <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DataDefinitionContent.ascx.cs"
解析器错误消息:此处不允许使用“CMS.Admin.WebUI.CustomControls.DataDefinitionContent、CoA.Admin.WebUI、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null”,因为它不扩展类“System.Web”。 UI.UserControl'。
第 1 行:<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DataDefinitionContent.ascx.cs"
采纳答案by Hyman Marchetti
Try putting your partial class in
尝试将您的部分课程放入
namespace CMS.Web
回答by Sofia Khwaja
I was getting this error when the name of the class that was extending the UserControl class was not the name used in ASP inclusion. I made the change to the class name and redeployed the solution. The problem was fixed.
当扩展 UserControl 类的类的名称不是 ASP 包含中使用的名称时,我收到此错误。我更改了类名并重新部署了解决方案。问题已解决。