Asp net aspx页面和webcontrol问题

时间:2010-04-14 09:34:53

标签: asp.net webforms

我有一个继承自Page的类,称为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);
  }
}

另一方面,我有一个名为Default的aspx页面,它继承自这个APage:

public partial class Default : APage
{

}

在此默认页面的设计部分,我有一个转发器:

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

此转发器是在基本APage加载事件中的数据源,但在此级别,此Web控件为空。

您是否知道为什么控件在基页中为空?

提前致谢。

最诚挚的问候。

何。

1 个答案:

答案 0 :(得分:2)

注意页面生命周期:

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

每个控件都在页面加载事件之后加载,因此在该阶段执行绑定操作并不好。你最好在PreRender期间进行这项操作。

相关问题