繁体   English   中英

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

[英]Why is my Repeater null in code behind?

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

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>

代码背后

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

设计师:

  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;
}

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

引用页面包含:

<ux:GalleryControl runat="server" ID="uxGalleryControl"/>

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

<add tagPrefix="ux" namespace="Site.UserControls" assembly="Site" />

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

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

<%@ Register Src="~/UserControls/GalleryControl.ascx" TagPrefix="ux" TagName="GalleryControl" %>

立即工作。

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

我有类似的问题,只是意识到有问题的转发器是在另一个转发器的(大规模)标头模板中。 重新排列标题模板,使所述转发器在外面,解决了问题......奇怪的是,虽然没有编译器错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM