ASP.NET Page Events and page cycle

Leave a Comment

ASP.NET developers consistently work with various events in their server-side code. Many of the events that they work with pertain to specific server controls. For instance, if you want to initiate some action
when the end user clicks a button on your Web page, you create a button-click event in your server-side
code.

In addition to the server controls, developers also want to initiate actions at specific moments when the ASP.NET page is being either created or destroyed. The ASP.NET page itself has always had a number of events for these instances. The following list shows you all the page events you could use in ASP.NET 1.0/1.1:
  1. AbortTransaction
  2. CommitTransaction
  3. DataBinding
  4. Disposed
  5. Error
  6. Init
  7. Load
  8. PreRender
  9. Unload
Besides the page events just shown, ASP.NET 2.0 adds the following new events:
  • InitComplete: Indicates the initialization of the page is completed.
  • LoadComplete: Indicates the page has been completely loaded into memory.
  • PreInit: Indicates the moment immediately before a page is initialized.
  • PreLoad: Indicates the moment before a page has been loaded into memory.
  • PreRenderComplete: Indicates the moment directly before a page has been rendered in the browser. 

You construct these new page events just as you did the previously shown page events. For example, you use the PreInit event.

If you create an ASP.NET 2.0 page and turn on tracing, you can see the order in which the main page events are initiated. They are fired in the following order:
  1. PreInit
  2. Init
  3. InitComplete
  4. PreLoad
  5. Load
  6. LoadComplete
  7. PreRender
  8. PreRenderComplete
  9. Unload
With the addition of these new choices, you can now work with the page and the controls on the page at many different points in the page-compilation process. You see these useful new page events in code examples throughout the book.

0 comments:

Post a Comment