2011-08-21 55 views
0

我有一個CompositeDataBoundControl定義如下:我的CompositeDataBoundControl有什麼問題?

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ReportSection.ascx.cs" Inherits="WebReports.ReportSection" %> 
<div class="report-section span-24"> 
    <h3> 
     <%= Title %></h3> 
</div> 

public partial class ReportSection : CompositeDataBoundControl 
{ 
    public string Title { get; set; } 
    protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding) 
    { 
     //throw new NotImplementedException(); 
     return 1; // JUst something to avoid exceptions. 
    } 
} 

然而,當我嘗試加載包含此控件的Web窗體,我得到以下分析器錯誤:

「WebReports.ReportSection」這裏不允許使用因爲它沒有擴展類「System.Web.UI.UserControl」。

這對我來說似乎很奇怪,因爲我覺得CompositeDataBoundControl是用作用戶控件的基類,還是它可能只用於服務器控件?

回答

0

它用於服務器控件,而不是用戶控件。 UserControls與其他控件(都是從TemplatedControl繼承的)相比,更類似於Pages。

您可以從MSDN description for CompositeDataBoundControl,它不是真正用於用戶控件,請參閱:

Represents the base class for a tabular data-bound control that is composed of other server controls.