I'm just starting a new project and I am getting some really weird stuff happening.
ASP.NET 3.5, VS2008.
I've tried rebuild, close VS, delete everything and get from svn again but I cannot understand why the repeater in the following is null on page_load.
I know this is going to be a headslapping moment. Help me out?
Markup:
<%@ 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>
Code behind
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();
}
}
Designer:
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;
}
Why is my repeater null? What the F is going on?
The referencing page has this:
<ux:GalleryControl runat="server" ID="uxGalleryControl"/>
The web.config has this (I've never had to do this before but my masterpage was complaining about not finding another user control).
<add tagPrefix="ux" namespace="Site.UserControls" assembly="Site" />
Like GridView, Repeater control does not have any EmptyDataTemplate and hence we need to make use of FooterTemplate and programmatically show (display) empty data message from code behind when no records are present. The HTML Markup consists of an ASP.Net Repeater control and a Button.
The Repeater control is used to display a repeated list of items that are bound to the control. The Repeater control may be bound to a database table, an XML file, or another list of items.
Yes, but it's not Category Wise. It's filtering Data. In my case all Particulars fields have type.
The Repeater control as the name suggests will repeat its content and hence it can be used to display data using any HTML element. In this article, the Repeater control will be populated from database and the data will be displayed as HTML table on the page.
After hours of head banging I have finally figured this out.
I was referencing the User controls in the web config as stated (I also tried the Register method with the Assembly). I think there's a weirdness with this method when the controls are in the same assembly. So referencing them like this:
<%@ Register Src="~/UserControls/GalleryControl.ascx" TagPrefix="ux" TagName="GalleryControl" %>
Worked immediately.
I hope anyone else with the same problem finds this useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With