1

Is there any kind of event out there that would allow for a preload post back event.

The reason I ask is I have a control that adds sibling controls to it on postback events, however, by the time it has loaded the post back its too late to add the new control to the control collection. Therefore, the controls are never updated correctly.

Thanks!

4

6 回答 6

1

Try the Init event.

于 2009-02-11T19:43:21.923 回答
0

覆盖CreateChildControls(确保调用 base!)。在您的回发事件处理程序中,确保您将应动态创建的控件列表存储在某处,因此当CreateChildControls在下一轮生命周期的早期被调用时,它将重新创建在最后一次回发上构建的控件。

于 2009-02-11T19:45:48.500 回答
0

这是一个快速破解。您可以随时查询 __EventTarget 和/或 init 中提交按钮的值,并可以动态加载控件。

但是这样做可能不合适,因为您的控制层次结构会改变并可能导致问题。

于 2009-02-11T19:49:43.047 回答
0

如上所述,必须在页面 Init 事件期间添加动态控件,以便可以在页面的 Viewstate 中正确处理它们。您可能还想关闭页面的 Viewstate,因为如果控件发生更改,它可能会向您触发错误。

于 2009-02-11T19:54:16.450 回答
0

此页面解释了回发中的事件顺序(以及每个事件中发生的情况),它不止一次地帮助了我。

我刚刚找到了这个链接,它也对你有用

于 2009-02-11T19:56:16.540 回答
0

如前所述,添加动态控件的适当位置是在 Init 事件中。这是一篇包含更多信息的文章。

动态 Web 控件、回发和视图状态

要更好地了解 ASP .NET 页面生命周期,请参阅:

ASP.NET 页面生命周期概述

于 2009-02-11T19:57:12.217 回答