Skip to Main Content
ASP.NET 4 24-Hour Trainer
book

ASP.NET 4 24-Hour Trainer

by Toi B. Wright
July 2010
Beginner content levelBeginner
552 pages
10h 14m
English
Wrox
Content preview from ASP.NET 4 24-Hour Trainer

Chapter 14A. Event Model in Web Forms

An event is something that occurs in response to an action. The ASP.NET Web Form framework provides a rich event model for the developer. In previous lessons you have seen that by simply double-clicking a button the IDE adds an event handler for the button's click event. In this lesson I show you how to handle other types of events, use one event handler for multiple objects, and force a postback to occur when a certain event is triggered.

Lesson 8A covered the page's life cycle. This is the sequence of events that are raised whenever a page is requested:

  • PreInit

  • Init

  • InitComplete

  • PreLoad

  • Load

  • LoadComplete

  • PreRender

  • PreRenderComplete

  • SaveStateComplete

  • Unload

By default, page events are automatically bound to methods with the name Page_event. This is true because by default AutoEventWireup="true" is included in the @Page directive for every page. If AutoEventWireup is set to false, you have to wire-up the events yourself. This is the code to add an event handler called LoadMyPage to handle the Load event of the page:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    this.Load += new EventHandler(LoadMyPage);
}

Like pages, server controls also have a life cycle. Server control events are processed after the pages Page_Init and Page_Load events. This is the sequence of events that is followed for every server control whenever a page is requested:

  • Init

  • Load

  • PreRender

  • DataBinding

  • Unload

  • Disposed

However, most server controls include additional events in their ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 4 24-Hour Trainer

ASP.NET 4 24-Hour Trainer

Toi B. Wright
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9780470596913Purchase bookExamplesErrata