2010-06-10 49 views
8

我剛剛開始一個新項目,我正在發生一些非常奇怪的事情。爲什麼我的Repeater在代碼後面爲空?

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" /> 
+0

很奇怪。你有沒有檢查你的.aspx.designer.cs文件的中繼器控制? 也許由於某種原因,設計者並沒有自動生成參考?我見過之前發生過。 – RPM1984 2010-06-10 00:50:06

+0

是的,它在那裏。更新的問題。 – 2010-06-10 00:54:19

+0

我剛剛嘗試創建一個具有相同效果的全新控件。引用它的頁面上有一個DropDownList,這很好。 – 2010-06-10 00:58:48

回答

14

經過數小時的頭撞我終於明白了這一點。

我正在引用Web配置中的用戶控件,如上所述(我也嘗試了使用Assembly的Register方法)。我認爲當控件位於同一個程序集中時,這種方法有點怪異。所以引用他們是這樣的:

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

立即工作。

我希望有同樣問題的其他人發現這個有用。

+0

謝謝,馬上解決了我的問題! – johna 2012-03-07 09:26:57

0

我有一個類似的問題,只是意識到有問題的中繼器在另一箇中繼器的(大量)頭模板中。 以這種方式重新排列標題模板,使得所述中繼器在外面,解決了問題... 奇怪的是,雖然沒有編譯器錯誤