开发者

Interesting ASP.NET Lifecycle Event Firing Error

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.


What you're seeing isn't an error. It's happening because that's the way it's supposed to happen:

The Init event of individual controls occurs before the Init event of the page.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜