c# – 基类包含字段,但类型与控件类型不兼容

前端之家收集整理的这篇文章主要介绍了c# – 基类包含字段,但类型与控件类型不兼容前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
基类包含字段’lbl’,但其类型(web.App_Code.CustomLabelControl)与控件类型(web.App_Code.CustomLabelControl)不兼容.

我以同样的方式完成了许多自定义控件,但是Hell这个错误让我很难.我有一个Web应用程序项目与App_Code目录中的下列类别在web.config中的类中的控件的tagprefix引用.现在我该怎么做?

Web.Config中

@H_403_6@<system.web> <pages> <controls> <add namespace="web.App_Code" tagPrefix="CControls"/>...

标记

@H_403_6@<form id="form1" runat="server"> <div> <CControls:CustomLabelControl runat="server" OnClickText="Welcome" ID="lbl"> </CControls:CustomLabelControl> </div> </form>

文件

@H_403_6@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(); } } }

试过这些

> The base class includes the field ‘btnLogin’,but its type (FoodOrder.App_Code.LinkButtonDefault) is not compatible
> http://support.microsoft.com/kb/919284
> The base class includes the field ‘ScriptManager1’,but its type (System.Web.UI.ScriptManager) is not compatible with the type of control (System.Web.UI.ScriptManager)

解决方法

尝试指定程序集名称: @H_403_6@<add tagPrefix="CControls" namespace="web.App_Code" assembly="web.App_Code" />

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

@H_403_6@<add tagPrefix="CControls" namespace="web.App_Code.CustomControls" assembly="web.App_Code.CustomControls" />

猜你在找的C#相关文章