
Stages of Page Processing | 49
Web Forms
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
When using the AddHandler, +=,orWithEvents/Handles techniques
for wiring up the standard events (Init, Load, etc.) manually, you
should add the AutoEventWireup attribute to your page’s @ Page
directive, with the value set to False. Otherwise, the event handlers
will be called more than once. Fortunately, new pages added to a
web project in Visual Studio .NET have this attribute set to False
by default.
ASP.NET Page and Control Events
Each stage of Web Forms processing shown in Figure 3-1 exposes particular
events that can be handled in your code. In this section, we’ll examine those
events in detail.
Init
The Init event, which is fired with each request, is used to initialize the page. If
variables need to be declared and initialized before the majority of page processing
begins, the event handler for the Init event is the place to do it. A good example of
this is that for C# web projects in Visual Studio .NET, the Page_Init event
handler is used to wire up other events handled by a page’s code-behind class.
The Page_Init handler, in turn, is wired up in the constructor for the code-behind
class.
It’s important to ensure that the logic performed in the Init event
handler is the same for each request to the page, particularly with
respect to adding