FREE & Commercial Dreamweaver MX Extensions from WebXeL.com Ltd
 
Web Design & Web Hosting


What order do events get executed?

Every time an ASP.NET page is viewed many tasks are being performed behind the scenes, one of these tasks being raising events at key points of the pages execution lifecycle, below is a list of the more commonly used events that are raised and what the state of the page and it's server controls will be at that point, this list does not include every event that's raised but does contain the most commonly used ones, for a more complete list you should consult the SDK documentation.

OnInit
The first event in our list to be raised is OnInit , when this event is raised all of the pages server controls are initialized with their property values. PostBack values are not applied to the controls at this time.

OnLoad
The next event to be raised is OnLoad, this is the most important event of them all as all the pages server controls will have their PostBack values applied by now so this point.

PostBack Events
Next all the PostBack events are raised, by PostBack events I am referring to any event that is raised only on a PostBack such as button click events and DropDownList item change events. These events are only raised page view is the result of a PostBack and the order that these events are raised can't be defined or relied upon, the only consistency with the order that PostBack events are raised is that they are all raised between the OnLoad and OnPreRender events.

OnPreRender
This event is raised just prior to the page or server controls html output being written into the response stream that's sent to the clients web browser, this is last chance you have to make any modifications, by this point all the server controls on the page have the final data applied, for instance any databound DropDownList‘s on the page are guaranteed to have their Items collection populated by now.

OnUnload
This is the last event in our list to be raised and you should destroy any un-managed objects and close any currently open database connection at this point. You can't modify any controls on the page at this point as the response stream has already been sent to the client web browser.

As each event of the page is raised it also automatically tells all it's child controls to raise their own implementation of the same event, in turn each of those controls will tell it's own child controls to do the same and so on down the control tree till all controls have done so, then execution flow is passed back to the main page class to continue onto the next event and the process is repeated for that event. You therefore know that when the pages OnLoad event is raised so too are all it's server controls OnLoad events.

 

Previous: So what's cool about events? Next: Dissect and explain an event procedure
 
Web Design Telephone Tel: 01738 444240  Web Design Fax Fax: 01738 560336  Web Design Email E-mail: webxel-dw.co.uk
© WebXeL.com Ltd
FREE & Commercial Dreamweaver MX Extensions from WebXeL.com Ltd