Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Page.LoadComplete meant for (in practice)

Tags:

asp.net

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?

like image 971
Simon_Weaver Avatar asked Jan 17 '09 09:01

Simon_Weaver


2 Answers

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.

like image 135
Arjan Einbu Avatar answered Oct 31 '22 17:10

Arjan Einbu


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".

like image 36
Cristian Libardo Avatar answered Oct 31 '22 19:10

Cristian Libardo