【发布时间】:2009-08-20 01:20:04
【问题描述】:
我正在从 ASP.NET 1.1 迁移,我曾经使用设计器订阅页面事件,该设计器在页面上添加了对 InitializeComponent 方法的订阅。
在 ASP.NET 2.0 中,如何从设计器订阅 Page 事件?
不使用设计师这似乎工作。
protected void Page_Init(object sender, EventArgs e) {
// The code, no safety here, just convention
}
// OR
protected override void OnInit(EventArgs e) {
base.OnInit(e);
// The code
}
订阅页面事件的推荐方式是什么?同样的问题也适用于 MasterPage。
此外,在 UserControl 上订阅事件的最佳方式是什么?当我在 UserControl 上声明 Page_XXX 时,该事件会被多次调用。
【问题讨论】:
-
停止使用设计器....说真的。
-
我没有,真的:)。我只想找到订阅事件的最佳方式,而不会出错(处理程序未调用或调用多次)。到目前为止,constructor 的订阅是最好的。但我必须以它们不会自动连接的方式命名事件。
标签: asp.net webforms event-handling