INFO: ASP.NET Page Framework Overview

Article translations Article translations
Article ID: 305141 - View products that this article applies to.
This article was previously published under Q305141
Expand all | Collapse all

On This Page

SUMMARY

This article provides an introduction to the ASP.NET page framework.

For additional ASP.NET overviews, refer to the following Microsoft Knowledge Base article:
305140 INFO: ASP.NET Roadmap

MORE INFORMATION

The ASP.NET page framework is a scalable programming model that you can use on the server to dynamically generate Web pages. The ASP.NET page framework is the successor to Active Server Pages. This article address the following page framework topics:

Page Life Cycle

Because the page framework is a stateless a and disconnected model, every time a client requests an .aspx page, many things occur during the page processing to make the process appear seamless to the client. It is important for you to know and to understand this staged execution sequence when you work with ASP.NET.

For more information about the page life cycle, refer to the following .NET Framework Software Development Kit (SDK) documentation:
Control Execution Lifecycle
http://msdn2.microsoft.com/en-us/library/aa719775(vs.71).aspx

Page Events

During the life cycle of an ASP.NET page, a few standard events that are exposed from the Page object are used frequently. The ASP.NET page framework automatically connects to (or wires up) appropriate delegate instances at run time for these methods. This saves you from having to write the necessary "glue code." The following list presents the delegate instances that are wired up at run time in the order in which they are fired:
  • Page_Init: During this event, you can initialize values or connect any event handlers that you may have.
  • Page_Load: During this event, you can perform a series of actions to either create your ASP.NET page for the first time or respond to client-side events that result from a post. The page and control view state have been restored prior to this event. Use the IsPostBack page property to check whether this is the first time that the page is being processed. If it is the first time, perform data binding. Also, read and update control properties.
  • Page_DataBind: The DataBind event is raised when the DataBind method is called at the page level. If you call DataBind on individual controls, it only fires the DataBind event of the controls beneath it.
  • Page_PreRender: The PreRender event is fired just before the view state is saved and the controls are rendered. You can use this event to perform any last minute operations on your controls.
  • Page_Unload: After a page has finished rendering, the Page_Unload event fires. This event is a good place to perform final cleanup work. This includes items such as the cleanup of open database connections, discarding objects, or closing those files that are open.
The following list outlines the events that are non-deterministic:
  • Page_Error: If an unhandled exception occurs during page processing, the Error event fires. The Error event gives you an opportunity to gracefully handle errors.
  • Page_AbortTransaction: Transaction events are useful if you want to indicate whether a transaction succeeds or fails. This event is commonly used for shopping cart scenarios in which this event can indicate the success or failure of an order. This event fires when a transaction has been aborted.
  • Page_CommitTransaction: This event fires when a transaction has been committed successfully.
The following code samples illustrate a declaration for the Page_Load event.

Visual C# .NET and Visual J# .NET
public void Page_Load()
{
         if (!Page.IsPostback){
	      //Do something.
         }
}
				
Visual Basic .NET
Public Sub Page_Load()
        If Not Page.IsPostBack Then
             'Do something.
        End If
End Sub
				
For more information about the page events, refer to the following .NET Framework SDK documentation:
Web Forms Page Processing Stages
http://msdn2.microsoft.com/en-us/library/wf922ts9(vs.71).aspx
For an overview of programming with these page events and server control events, refer to the following .NET Framework SDK documentation:
Programming Web Forms
http://msdn2.microsoft.com/en-us/library/aa984181(VS.71).aspx

Page Directives

Page directives specify optional settings that the Page Compiler uses when it processes files. Page directives are located at the top of a page file and use the following syntax:
<%@ directive {attribute=value}* %>
				
ASP.NET pages support the following directives:
  • @ Page
  • @ Implements
  • @ Import
  • @ Register
  • @ Assembly
  • @ Reference
  • @ OutputCache
Each directive in turn supports one or more attribute-value pairs, which are not case-sensitive.

For more information about the page directives, refer to the following .NET Framework SDK documentation:
Directive Syntax
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconpagedirectives.asp

Inline Versus Code-Behind Programming Models

ASP.NET supports two modes of page development:
  • Page logic code that is written inside <script runat=server> blocks within an .aspx file and dynamically compiled the first time the page is requested on the server.
  • Page logic code that is written within an external class that is compiled prior to deployment on a server and linked "behind" the .aspx file at run time.
For additional information about inline and code-behind programming models, click the article number below to view the article in the Microsoft Knowledge Base:
303247 INFO: ASP.NET Code-Behind Model Overview

Properties

Article ID: 305141 - Last Review: May 22, 2007 - Revision: 4.8
APPLIES TO
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual J# .NET 2003 Standard Edition
Keywords: 
kbhttpruntime kbinfo kbwebforms KB305141

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com