 |
|
 |
 |
| The .NET Page Lifecycle, Part I |
|
|
Iron Speed Designer creates web pages derived from the ASP.NET Page class. When an ASP.NET
web page is requested from the web server, the code-behind class for the page goes through a
sequence of steps to initialize and load the user interface controls.
- Razi Mohiuddin, President of Iron Speed, Inc.
February 14, 2006
Iron Speed Designer V3.2
|
|
| Introduction |
Iron Speed Designer creates standard web pages that are derived from the ASP.NET Page
class. When an ASP.NET web page is requested from the web server, the code-behind class
for the page goes through a sequence of steps to initialize and load the user interface controls,
read the data from the database and display the page.
This sequence of steps is called the page lifecycle as shown below:
- Initialization: During this stage the page and all of the controls within the page (control hierarchy) are instantiated. This includes any tables, textboxes and buttons.
- Data Binding: The data binding stage is where the data for the controls is loaded from the data-source and "bound" to each of the controls.
- Loading: The controls and the associated data of the controls are initialized.
- Event Handling: Post-back events caused by server controls will be handled.
- Rendering: The HTML of the page and all controls are sent to the browser for rendering.
All pages generated by Iron Speed Designer derive from the Microsoft .NET Frameworkâs Page class, so
they follow the same page lifecycle described above. The classes generated by Iron Speed Designer extend
the Page class to support loading data from the database and to provide more enhanced user interface controls
that support data type formatting and validation.
Overrides and Events
At each state of the page lifecycle, the Microsoft .NET Framework sends an event notification to
the page. You can handle an event to customize any aspect of the page before it is displayed to
the user. By handling an event, you can add functionality to your page, but cannot replace the existing
functionality that is already provided by the underlying classes.
Unlike event handling, overriding a method for a class allows you to replace the underlying functionality
being performed. For example, you can override the DataBind method of a page class to read the data from
the database and bind it to each of the controls. If you override a method, you have a choice of calling
the base method or simply replacing all of the functionality provided by the base class.
Note that event notifications are sent after the completion of each phase. For example, the Init event is
sent when the initialization of all the controls is complete and the Load is sent after the loading of the
data and the controls of the page is completed.
|
| Page Control Hierarchy |
|
All web pages in Microsoft .NET Framework contain a number of user interface controls that are
initialized at the server side and are called server controls. Since server controls can have
children, and each of their children may have children, and so on, a control and its descendents
form a tree of controls. This tree of controls is called the control hierarchy. The root of the
control hierarchy for a .NET web page is the Page-derived class. Iron Speed Designer generates a
hierarchy of controls for each of the pages.
The loading of the data from the database is delegated by the page to the Table Control or the
Record Row Control classes. Since you can have a number of tables and records displayed on a page,
there can be multiple Table Control and Record Control classes within a page. Each of the classes is
responsible for loading its data from the database based on the query you specified and any search, filter
and pagination settings selected by the end user.
The filter, field value, search and other user interface controls do not load data from the
database directly. Instead they rely on the Table Control and Record Control classes to load
the data.
|
| Table Control and Record Control Lifecycle |
|
The Table Control and Record Control are user interface controls and have a lifecycle of
their own, just like the lifecycle of each of the controls on a page. It is important to
understand the lifecycle of the table and record control classes since the page delegates the
responsibility of reading the data from the database and retrieving and validating the data from
the user interface prior to saving it in the database.
The query used to read data from the database is a composite query that is formed based on
the static Where clause specified by the developer and the dynamic settings specified by the
end user. The static query might be:
When the end user views the information, he or she might search for some information
within the table, further filter by another field, sort by a column and display the third
page of information. In this case, the query might look something like:
During the lifecycle of a table or record control, you have an opportunity to further modify
the query before it is executed by handling the PreRunQuery event. You can also review the data
retrieved and make any changes before presentation to the user, or calculate values that are dependent
on the rows retrieved by handling the PostRunQuery event. Please note that the query only returns the
rows that are being displayed on the web page, not all of the rows that would be returned by the query.
|
| About the Author |
Razi Mohiuddin
Co-Founder, President & CEO of Iron Speed, Inc.
Mr. Mohiuddin co-founded numerous Internet and software companies, including Onsale, Inc.
(later Egghead.com and now Amazon.com), Ambia Corporation, an electronic document publishing
software company later acquired by Infodata Systems Inc., and Software Partners, Inc., a software
consulting company that developed StreetSmart, e.Schwab, FundMap, SchwabLink and Retirement Planner
software for Charles Schwab & Co.
Mr. Mohiuddin earned his BS in Computer Science from the University of Illinois, Chicago.
|
|
|
|