有趣的 ASP.NET 生命周期事件触发错误
我遇到了一个有趣的生命周期事件错误,想象一下这样的代码层次结构:
Page 1
User Control 2
User Control 3
其中每个项目都是此顺序的子项目。我希望 Page 1 首先触发其 oninit,然后是 User Control 2,然后是 User Control 3。但这并没有发生;实际上,在这种情况下,用户控件 3 首先触发 init。我将其中的每一个都继承自一个特殊的基类,并且有一些需要按顺序运行的管道代码。知道为什么会发生这种情况吗?
谢谢。
I'm having an interesting lifecycle event error, imagine a code hierarchy like this:
Page 1
User Control 2
User Control 3
Where each of these items is a child in this order. I expect Page 1 to fire its oninit first, then User Control 2, then User Control 3. But this doesn't happen; actually, in this scenario, User Control 3 fires init first. I have each of these inheriting from a special base class, and have some plumbing code that needs to run in order. Any idea why this is happening?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您所看到的并不是错误。发生这种情况是因为这就是它应该发生的方式:
What you're seeing isn't an error. It's happening because that's the way it's supposed to happen:
正如其他人所指出的,Init 事件是从下往上触发的,而后来的事件(例如 Load)是从上往下触发的。
As pointed out by others, the Init events fire from the bottom up, while later events (such as Load) fire from the top down.
如何引发事件的一般规则是,初始化事件从最内层控件到最外层控件引发,所有其他事件从最外层控件到最内层控件引发。
The general rule for how events are raised is that the initialization events are raised from the innermost control to the outermost one, and all other events are raised from the outermost control to the innermost one.