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 8A. The Page Life Cycle in Web Forms

Every time a browser requests a page from a web application using the ASP.NET Web Forms framework, the page must complete the full page life cycle. In this lesson I list all of the steps in the page life cycle, show you how to run a trace of your page to see what is happening during each stage of the page's life cycle, and show you how to determine if a page is a postback.

All of the lessons so far have only used the Page_Load() event to add code to the page. Many more events are available during the page's life cycle. This is the sequence of events, in the order that they are raised, whenever a page is requested:

  • PreInit

  • Init

  • InitComplete

  • PreLoad

  • Load

  • LoadComplete

  • PreRender

  • PreRenderComplete

  • SaveStateComplete

  • Render

  • Unload

    Note

    Render is included on the list of events even though it is not an event; it is a method. The Page object calls the Render method on each control to write out the control's markup to the page.

PAGE-LEVEL TRACING

A simple way to view the page life cycle for your page is to enable tracing. You enable page-level tracing by adding a trace="true" attribute to the @Page directive at the top of the page. This is an example of an @Page directive that has been modified to enable tracing:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"
    AutoEventWireup="true" CodeBehind="Default.aspx.cs"
    Inherits="Lesson8a._Default" Trace="true" %>

Figure 8A-1 shows the Request Details and Trace Information that is added to the bottom ...

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