【问题标题】:Asp net aspx page and webcontrol issueAsp net aspx 页面和 webcontrol 问题
【发布时间】:2010-04-14 09:34:52
【问题描述】:

我有一个继承自 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 控件为空。

你知道为什么基页中的控件为空吗?

提前致谢。

最好的问候。

何塞。

【问题讨论】:

    标签: asp.net webforms


    【解决方案1】:

    注意页面生命周期:

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

    每个控件都是在页面Load事件之后加载的,所以在那个阶段进行绑定操作是不好的。您最好在 PreRender 期间执行此操作。

    【讨论】:

      猜你喜欢
      • 2012-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      相关资源
      最近更新 更多