加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 18:11:36 所属栏目:百科 来源:网络整理
导读:基类包含字段’lbl’,但其类型(web.App_Code.CustomLabelControl)与控件类型(web.App_Code.CustomLabelControl)不兼容. 我以同样的方式完成了许多自定义控件,但是Hell这个错误让我很难.我有一个Web应用程序项目与App_Code目录中的下列类别在web.config中的类
基类包含字段’lbl’,但其类型(web.App_Code.CustomLabelControl)与控件类型(web.App_Code.CustomLabelControl)不兼容.

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

Web.Config中

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

标记

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

类文件

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)

解决方法

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读