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.

 

 

Published Sunday, May 25, 2003 3:11 AM by vga

Comments

# re: New LoadFinished event for Page

Saturday, May 24, 2003 11:54 PM by Frans Bouma
shouldn't code relying on a postback (f.e. a button is clicked) be placed in a routine that is fired from the eventhandler of that button f.e.?

# re: New LoadFinished event for Page

Sunday, May 25, 2003 5:47 AM by Paschal
Frans yes but the Page load event is still executed whatever the Event you link to the button.
I use intensively now Prerender event, but the event cycle can be quite complex when you have all your controls with their own events.

# re: New LoadFinished event for Page

Sunday, May 25, 2003 10:48 AM by vga
Hi Frans,

Not always. The code that goes into an eventhandler is just for handling that specific event and won't run on every postback (ie. if the button wasn't clicked). So you still need a place where to put "general" code that must always run and depend on the updated values (ie. PreRender).

# re: New LoadFinished event for Page

Monday, May 26, 2003 8:24 AM by Nikhil Kothari
Yep, we've added an event for this purpose - LoadComplete.

We've also added various other events in the page lifecycle that should be useful to page and control developers.

# re: New LoadFinished event for Page

Thursday, May 29, 2003 12:58 AM by venu
this is testing

# re: New events! [To Nikhil]

Saturday, May 31, 2003 1:14 PM by Gauthier
FROM Nikhil Kothari:
>Yep, we've added an event for this purpose -
>LoadComplete.
>
>We've also added various other events in the
>page lifecycle that should be useful to page
>and control developers.

I've a some Event schemes for different control type that I've developped myself, for exemple I've a Skinned usercontrol that does that:
CreateChildControls():
-LoadSkin();
-InitializeSkin();
-RegisterEvents();
-Controls.Add(this.skin);

another one is a simple Databound scheme:
OnDataBinding(EventArgs e)
-EnsureEditorMode();
-EnsureRights();
-EnsureChildControls();
-if(!Page.IsPostBack)
- BindItemToControl();
-else
- BindControlToItem();

antoher one for the databoundtemplatedlist controls...

Does some of the new events will help to maintain a simple event scheme?

I find that some event schemes I use are very usefull when implementing multiple similar controls from an abstract class, and since I'm interested in such schemes I would like to know a bit more on your comment.

Thanks!

# re: New LoadFinished event for Page

Sunday, June 20, 2004 4:24 PM by Andreas Rudischhauser
Move To PreRender..... :-S

Isn't it better to check in PreRender if the Property changed and then call EnsureChildControls or soemthing?

# re: New LoadFinished event for Page

Tuesday, September 12, 2006 10:45 PM by Sabrina

As an ASP.NET 1.1 solution, what I do is, in the Base Page that other aspx pages derive from, I override the RaisePostBackEvent() method and raise a custom event. This way, even UserControls on the Page can wire handlers to the event to respond at the appropriate time. Your thoughts?

protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)

{

  base.RaisePostBackEvent (sourceControl, eventArgument);

  this.OnPostBackEventsComplete(new EventArgs());

}

# re: New LoadFinished event for Page

Saturday, August 04, 2007 4:57 PM by diller

nice  site...  look on my site

http://www.desklamp.fora.pl - desk lamp

http://www.lampshades.fora.pl - lamp shades

# re: New LoadFinished event for Page

Tuesday, December 02, 2008 11:57 AM by Asina

<a href= bestpre.com ></a>

# re: New LoadFinished event for Page

Friday, December 05, 2008 7:00 PM by Semil

<a href= spiritez.com ></a>

# re: New LoadFinished event for Page

Friday, December 26, 2008 5:59 AM by jyner_gz

<a href= membres.lycos.fr/maffals >genetic disorters</a>

# re: New LoadFinished event for Page

Sunday, January 25, 2009 12:55 PM by Serega4356

������� ����� ������ � ������� ������� � ���������. ���� ��������� �������� <A href="gorasofta.spb.ru/"target=_blank>

<FONT size=1>���� �����</FONT></A>

# re: New LoadFinished event for Page

Saturday, February 28, 2009 11:00 PM by jyner_wv

<a href= http://adultchatsfinder.com >find partner</a>

# re: New LoadFinished event for Page

Thursday, April 09, 2009 12:13 PM by nick_ricchi

www.message_chicobo.com

# re: New LoadFinished event for Page

Wednesday, April 22, 2009 6:21 PM by Mery-hi

<a href= <div align=center><h3>Error. Page cannot be displayed. Please contact service provider for more details.</h3></div> ></a>

# re: New LoadFinished event for Page

Wednesday, April 29, 2009 6:53 PM by Mery-cn

<a href= <div align=center><h3>Error. Page cannot be displayed. Please contact service provider for more details.</h3></div> ></a>

# re: New LoadFinished event for Page

Saturday, September 15, 2012 1:12 PM by images longford

 In my opinion you are not right. Let's discuss.

P.S. Please review our <a href="www.goloads.com/.../winserver">icons for Windows</a>  and windows13icons.

# re: New LoadFinished event for Page

Monday, September 17, 2012 5:02 PM by icons

 There are still more many variants

P.S. Please review <a href="ikonaluk.deviantart.com/.../a>

# re: New LoadFinished event for Page

Monday, September 17, 2012 5:41 PM by icons

 Amusing state of affairs

P.S. Please review <a href="martinking33.deviantart.com/.../Icon-Design-Pack-312656618">Icon Design Pack from martinking33</a>

# re: New LoadFinished event for Page

Monday, September 17, 2012 6:20 PM by icons

 I apologise, but, in my opinion, you are not right. I am assured. Let's discuss it. Write to me in PM, we will communicate.

P.S. Please review <a href="yourmailkept1.deviantart.com/.../Blue-Icon-Library-312562805">Blue Icon Library from yourmailkept1</a>

# re: New LoadFinished event for Page

Monday, September 17, 2012 7:36 PM by icons

 Certainly.

P.S. Please review <a href="iconicon40.deviantart.com/.../Glossy-Toolbar-Icons-311181039">Glossy Toolbar Icons from iconicon40</a>

# re: New LoadFinished event for Page

Tuesday, September 18, 2012 4:09 AM by icon bundle

 Very good message

P.S. Please review <a href="tonoficons.deviantart.com/.../Basic-Icons-for-Vista-278685327">Basic Icons for Vista from tonoficons</a>

# re: New LoadFinished event for Page

Tuesday, September 18, 2012 4:54 AM by icon clip art

 Yes, really. And I have faced it.

P.S. Please review <a href="ikonga.deviantart.com/.../Business-App-Tab-Bar-Icons-288877846">Business App Tab Bar Icons fropm Ikonga</a>

# re: New LoadFinished event for Page

Tuesday, September 18, 2012 5:40 AM by icon collection

 I apologise, but, in my opinion, you are not right. Write to me in PM, we will communicate.

P.S. Please review <a href="tsenitelikon.deviantart.com/.../Desktop-Crystal-Icons-282843564">Desktop Crystal Icons from tsenitelIkon</a>

# re: New LoadFinished event for Page

Tuesday, September 18, 2012 10:05 AM by icon designs

 Willingly I accept. An interesting theme, I will take part. Together we can come to a right answer. I am assured.

P.S. Please review <a href="popavidi3nr.deviantart.com/.../Desktop-Education-Icons-297073029">Desktop Education Icons from popavidi3nr</a>

# re: New LoadFinished event for Page

Tuesday, September 18, 2012 12:03 PM by icon set

 I recommend to you to visit on a site, with a large quantity of articles on a theme interesting you. I can look for the reference.

P.S. Please review <a href="database-icons.deviantart.com/.../Add-v2-Icon-133793215">Add v2 Icon from database-icons</a>

# re: New LoadFinished event for Page

Tuesday, September 18, 2012 12:57 PM by icons

 You have quickly thought up such matchless phrase?

P.S. Please review <a href="designesticons.deviantart.com/.../Metro-Style-WP7-Icons-278989682">Metro Style WP7 Icons from designesticons</a>

# re: New LoadFinished event for Page

Tuesday, September 18, 2012 1:52 PM by icons

 Rather useful piece

P.S. Please review <a href="ikonod.deviantart.com/.../Classic-Menu-Icons-287636388">Classic Menu Icons from Ikonod</a>

# re: New LoadFinished event for Page

Friday, September 21, 2012 5:24 PM by icons

 Willingly I accept.

P.S. Please review <a href="tonoficons.deviantart.com/.../Einfache-Toolbar-Icons-278681201">Einfache Toolbar Icons from tonoficons</a>

# re: New LoadFinished event for Page

Saturday, September 22, 2012 10:45 PM by icons pack

 Between us speaking, in my opinion, it is obvious. I would not wish to develop this theme.

<a href="www.hpixel.com/.../a>

# re: New LoadFinished event for Page

Monday, September 24, 2012 4:42 AM by icons download

 The safe answer ;)

<a href="www.hpixel.com/.../a>

# re: New LoadFinished event for Page

Tuesday, October 09, 2012 8:42 PM by icons download

<a href="beelin.kiev.ua/showthread.php Rather amusing idea</a>

Leave a Comment

(required) 
(required) 
(optional)
(required)