基类包括字段但类型与控件类型不兼容

The base class includes the field 'lbl', but its type (web.App_Code.CustomLabelControl) is not compatible with the type of control (web.App_Code.CustomLabelControl).

我以同样的方式做了很多自定义控件,但地狱这个错误让我疯了。 我有一个Web应用程序项目,在App_Code目录中具有以下类,在web.config中为类中的控件提供了tagprefix引用。 现在我该怎么做?

Web.Config中

    ... 

标记

 

类文件

 namespace web.App_Code { public class CustomLabelControl : Control, IPostBackEventHandler, IPostBackDataHandler { private string _onClickText; public CustomLabelControl() { } public string OnClickText { get { return _onClickText; } set { _onClickText = value; } } public void RaisePostBackEvent(string eventArgument) { throw new System.NotImplementedException(); } public bool LoadPostData(string postDataKey, NameValueCollection postCollection) { throw new System.NotImplementedException(); } public void RaisePostDataChangedEvent() { throw new System.NotImplementedException(); } } } 

试过这些

  • 基类包含字段’btnLogin’,但其类型(FoodOrder.App_Code.LinkBut​​tonDefault)不兼容

  • http://support.microsoft.com/kb/919284

  • 基类包括字段’ScriptManager1’,但其类型(System.Web.UI.ScriptManager)与控件类型(System.Web.UI.ScriptManager)不兼容

尝试指定程序集名称:

  

我会考虑为您的自定义控件创建一个专用命名空间,只是为了清晰起见。 也许像web.App_Code.CustomControls

  

Unckeck构建(和发布)选项“允许此预编译站点可更新”

它可能不适用于运行时,因此请选中“使用固定命名和单页程序集”选项,它解决了我的情况:)

这是关于此错误的有用链接: http : //forums.asp.net/t/960707.aspx

请参考web.conf中的ascx用户控件,而不是像这样的aspx页面:

  

这解决了我的问题。

我知道这是旧的,但我尝试将文本框更改为标签控件时遇到了同样的错误。 我只是将控件的ID从“胰岛素”改为“胰岛素2”,这解决了问题。 我不确定它为什么会起作用,但这对微软来说可能是一个问题。

在进一步研究之后,我注意到如果我关闭了我在Visual Studio中工作的页面的选项卡然后重新打开它,错误就一起消失了? 我希望这有助于某人。