New LoadFinished event for Page
Note: this entry has moved.
Lots of people starting to learn ASP.NET tend to
heavily depend on the Load
event. They find quite naturally to write most core
logic into Load
until they realize their code just doesn’t work as
expected and start coding all kind of hacks.
A common example of this mistake is to write code in Load
that depends on values that will be updated only after
postback data has been processed; but as Load
fires before postback data (2nd try) and RaiseChangedEvents
and RaisePostBackEvent
are processed such code won’t work properly -- and
that is when people start writing hacks like peeking
at the
Forms
collection to get the updated value; the WebForm model
is not followed and bad things happen when you do that J
If you still doesn’t get the scenario I’m talking about
take a look at this post.
The solution to this? Move your code to PreRender, sure; but this doesn’t sound very intuitive to a
beginner.
I believe that adding a brand new event to Page, something like LoadFinished
that fires right after 2nd try postback data and changed
& postback events are processed and right before PreRender
would be a more natural choice where to put such
code.
You could then market this new event as the one that
fires when the page has completely finished its loading
and the place where any code can safely depend on all
postback data to be updated.