元素'CompositeBoundField'不是一个已知元素。(试图扩展BoundField服务器控件)

问题描述 投票:3回答:2

VS2010, .Net 4.0

在尝试扩展asp.net BoundField服务器控件,如这里所述。http:/iridescence.nopostFixingBoundFieldSupportforCompositeObjects.aspx。

我已经创建了一个班级。

using System.Web.UI;
using System.Web.UI.WebControls;

namespace CustomControls
{ 
    public class CompositeBoundField : BoundField
    {
        protected override object GetValue(Control controlContainer)
        {
            object item = DataBinder.GetDataItem(controlContainer);
            return DataBinder.Eval(item, this.DataField);
        }
    }
}

我已经在我的页面上注册了它

<%@ Register TagPrefix="cc" Namespace="CustomControls" %>

...在那个页面上,我试图这样使用它。

<asp:GridView ID="gridDataSource" runat="server">
    <Columns>
        <cc:CompositeBoundField DataField="Application.ApplicationName" HeaderText="ApplicationName" />
    </Columns>
    </asp:GridView>

然而,我收到了一个编译器警告。

Element 'CompositeBoundField' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.    

当我运行的时候,我得到了错误信息

Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: Unknown server tag 'cc:CompositeBoundField'.

你知道我做错了什么吗?

我试过这样做。http:/blog.tentaclesoftware.comarchive2010072195.aspx。

asp.net visual-studio visual-studio-2010
2个回答
4
投票

在Register声明中,Assembly是强制性的。

<%@ Register Namespace="CustomControls" TagPrefix="cc" Assembly="MyCompany.MyApp.WebApp" %>

1
投票

检查Assembly属性是否包含完整的强名,例如: ...

   <%@ Register Assembly="MyCompany.MyApp.WebApp, Version=3.42.0.0, Culture=neutral, PublicKeyToken=674cf0e5bf72fa08"
                TagPrefix="cc"
                Namespace="CustomControls"  @%>

此外,你可能会遇到将两个Assembly映射到同一个TagPrefix的问题。 不要这样做。 它可能会导致不可预知的结果,并可能突然停止工作。

© www.soinside.com 2019 - 2024. All rights reserved.