views:

19

answers:

1

Hello,

I have a class that inherits from Page, called APage.

public abstract class APage: Page
{
  protected Repeater ExampleRepeater;
  ....
  protected override void OnLoad(EventArgs e)
  {
        if (null != ExampleRepeater)
        {
                ExampleRepeater.DataSource = GetData();
                ExampleRepeater.DataBind();
        }
        base.OnLoad(e);
  }
}

For other hand i have an aspx page called Default that inherits from this APage:

public partial class Default : APage
{

}

on the design part of this Default page, i have a repeater:

<asp:Repeater ID="ExampleRepeater" runat="server">
    <ItemTemplate>
        <%# DataBinder.Eval(Container.DataItem, "Name") %><br/>
    </ItemTemplate>
</asp:Repeater>

This repeater is datasourced at the base APage load event, but at this level this web control is null.

Do you have any idea why the control is null in the base page?

Thanks in advance.

Best Regards.

Jose.

+2  A: 

Pay attention to the page life-cycle:

http://msdn.microsoft.com/en-us/library/ms178472.aspx

Each control is loaded after the page Load event, so it's not good to perform binding operations at that stage. You'd better do this operation during PreRender.

mamoo