tags:

views:

3273

answers:

3

In the ASP.NET Page LifeCycle there is the Page.LoadComplete event.

The MSDN documentation says 'Use this event for tasks that require that all other controls on the page be loaded'. What exactly might this be? What would a 'best practice' say that LoadComplete should be used for?

+1  A: 

Say you have multiple controls that prepare some data in the load event. If you want to take action on that data in the load step of the ASP.NET lifecycle you need to have a way to execute after all the other load's have run. Hence the "load complete". There's also an "init complete".

Cristian Libardo
+1  A: 

When you hook up several methods to the Load event you don't know the order they will get called. So you have the PreLoad, Load and LoadComplete events to have some more control as to in what order your code gets called.

The use of this might not always be clear when working only with your page class. When working with controls however, with the need to have some code running at Load time, you might want to make it run right before or right after what would normally happen in the Load event. Then you can use the PreLoad and LoadComplete methods.

As simon mentioned, the same pattern is followed with the Init event...

More information can be found in this MSDN article about the ASP.NET Page Lifecycle

EDIT: It seems, from the MSDN article that LoadComplete is called AFTER your control events like Button.Click have been raised.

Arjan Einbu
+1  A: 

Here is one example where I was trying to use Page_Load and someone correctly pointed out that LoadComplete would be better.

nshaw