为什么我的Repeater在代码中为空?

Rob*_*ett 9 c# asp.net

我刚刚开始一个新项目,我发现了一些非常奇怪的事情.

ASP.NET 3.5,VS2008.

我已经尝试重建,关闭VS,删除所有内容并再次从svn获取,但我无法理解为什么以下的转发器在page_load上为null.

我知道这将是一个令人头疼的时刻.帮帮我?

标记:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GalleryControl.ascx.cs" Inherits="Site.UserControls.GalleryControl" %>
<asp:Repeater ID="rptGalleries" runat="server">
    <HeaderTemplate><ul></HeaderTemplate>
    <ItemTemplate>
       <li>wqe</li>
    </ItemTemplate>
    <FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)

代码背后

public partial class GalleryControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        rptGalleries.DataSource = new[] {1, 2, 3, 4, 5};
        rptGalleries.DataBind();
    }
}
Run Code Online (Sandbox Code Playgroud)

设计师:

  public partial class GalleryControl {

    /// <summary>
    /// rptGalleries control.
    /// </summary>
    /// <remarks>
    /// Auto-generated field.
    /// To modify move field declaration from designer file to code-behind file.
    /// </remarks>
    protected global::System.Web.UI.WebControls.Repeater rptGalleries;
}
Run Code Online (Sandbox Code Playgroud)

为什么我的转发器为空?F正在发生什么?

引用页面包含:

<ux:GalleryControl runat="server" ID="uxGalleryControl"/>
Run Code Online (Sandbox Code Playgroud)

web.config有这个(我以前从来没有这样做,但我的主页抱怨没有找到另一个用户控件).

<add tagPrefix="ux" namespace="Site.UserControls" assembly="Site" />
Run Code Online (Sandbox Code Playgroud)

Rob*_*ett 15

经过几个小时的敲击,我终于弄明白了.

我正在引用Web配置中的用户控件(我也尝试了使用Assembly的Register方法).我认为当控件在同一个程序集中时,这种方法很奇怪.所以引用它们是这样的:

<%@ Register Src="~/UserControls/GalleryControl.ascx" TagPrefix="ux" TagName="GalleryControl" %>
Run Code Online (Sandbox Code Playgroud)

立即工作.

我希望有同样问题的其他人发现这很有用.