Brian Mains
Brian Mains

Reputation: 50728

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.

Upvotes: 1

Views: 186

Answers (3)

ukhardy
ukhardy

Reputation: 2104

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.

Upvotes: 1

Quick Joe Smith
Quick Joe Smith

Reputation: 8222

As pointed out by others, the Init events fire from the bottom up, while later events (such as Load) fire from the top down.

Upvotes: 1

LukeH
LukeH

Reputation: 269278

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.

Upvotes: 2

Related Questions