I have a custom base page class:
//MobileFunnelPage.cs
public abstract class MobileFunnelPage : Page
{
public virtual Repeater myRepeater{get;set;}
}
Then I have a page that inherits that page:
//ConcreteMobileFunnelPage.aspx.cs
public class ConcreteMobileFunnelPage: MobileFunnelPage
{
protected override void Page_Load(object sender, EventArgs e){
myRepeater.DataSource = new string[]{"Error 1","Error 2","Error 3"};
myRepeater.DataBind();
}
}
With the following markup:
//ConcreteMobileFunnelPage.aspx
<%@ Page Title="ConcreteMobilePage!" Language="C#" AutoEventWireup="true" CodeBehind="ConcreteMobileFunnelPage.aspx.cs" inherits="MyNamespace.ConcreteMobileFunnelPage" %>
...
<asp:Repeater ID="myRepeater" runat="server" Visible="false">
<HeaderTemplate>
<div>
<span>
</HeaderTemplate>
<ItemTemplate><li><%# Container.DataItem %></li></ItemTemplate>
<FooterTemplate>
</span>
</div>
</FooterTemplate>
</asp:Repeater>
The asp.net designer is constantly regenerating and adding protected variables for myRepeater in the designer.cs file:
//ConcreteMobilFunnelPage.aspx.designer.cs
protected global::System.Web.UI.WebControls.Repeater myRepeater;
This causes a problem because it is not overriding the inherited myRepeater property, it is hiding it. Is there a way to get the designer to honor that myRepeater inherited property?
It’s a bit more wordy, but I think the simplest workaround is to make the property abstract and implement it with the generated field as the backing field:
(Here myRepeater is the protected auto-generated field, and I’ve renamed the public property to MyRepeater)
As an aside, you should probably remove the setter, I don’t think it serves any purpose here.