Section 6.1. The Page

6.1. The Page

An ASP.NET page consists of, at the minimum, a single file with an extension of .aspx though, typically, other files will be associated with the page, as we will describe. In the parlance of VS2005, this .aspx file is called the content file because it contains primarily the visual content of the page, i.e., HTML, text, and ASP.NET server controls.

Any content in the content file that is not part of a server control or server-side code is treated as a normal HTML file. It is passed from the server to the browser exactly as is, so the browser can deal with as it would any other HTML.

The .aspx file can contain script blocks. These are written in a scripting (non-compiled) language, such as JavaScript or VBScript, which will execute client side, meaning on the browser. It may also contain server-side code blocks, written in any .NET supported language, such as C# or VB2005, though these code blocks are more commonly contained in a separate code-behind file, as will be described in the next section.

When a browser requests the .aspx file from a web server, the server processes the page. If it is the first time that the page has been requested since the web application started, the ASP.NET runtime will compile from the page a Page class that derives from the base System.Web.UI.Page class. The compiled class contains all the control declarations and code that make up the page, including properties , event handlers, and other methods .

Everyone knows what an application is, more or less. Still, an ASP.NET application is defined more rigorously in Chapter 18.


The class is then compiled into an assembly, which is what is actually run by the Framework runtime to render output to the client. That assembly is cached in server memory, so subsequent calls to the page do not require the compilation step, and the request can be serviced more quickly.

You will notice this lag time the first time a page is viewed . It can be significant for complex pages. ASP.NET Version 2.0 adds the ability to pre-compile all the pages of a web site to avoid this problem after deployment. Deployment will be covered in Chapter 19.


The name of the compiled class is derived from the name of the .aspx file. If you keep the default name for a VS2005 content page, default.aspx , the class name will be _default . For any other page name, the class name will be same as the page name minus the extension, so SomePage.aspx will inherit from a class called SomePage .

For an .aspx file to be processed by the ASP.NET runtime, it must have a page directive as the first line in the file. Directives will be covered in detail later in this chapter, but for now the important point is that they provide information to the compiler, such as the language in use, the name of the code-behind file, if any, and the name of the Page class.

The class hierarchy for the Page class is shown in Figure 6-1. Since the Page class derives from Control , as do all the ASP.NET server controls, it shares all of the members of the Control class, including properties such as Controls , EnableTheming , EnableViewState , ID , SkinID , and Visible , all of which are described in Table 3-1. It also has a number of properties of its own, the most commonly used of which are listed in Table 6-1.

Table 6-1. Commonly used Page class properties

Name

Type

Get

Set

Description

Application

Application

 

Retrieves a reference to the Application object for the current request.

Cache

Cache

 

Retrieves the Cache object of the application.

ClientQueryString

string

 

Retrieves the query string portion of the URL.

Controls

ControlCollection

 

Retrieves a reference to the collection of Controls on the page. Inherited from Control .

ErrorPage

string

The name of the page to redirect the browser to when there is an error. See Chapter 7 for coverage of error handling.

IsCrossPagePostBack

Boolean

 

If true , this page has called another page.

IsPostBack

Boolean

 

If true , this page is being loaded in response to a client post. If false , it is being loaded for the first time.

IsValid

Boolean

 

If true , validation succeeded for all the controls on the page.

MaintainScrollPositionOnPostback

Boolean

 

If true , the browser positioning of the page will be preserved across postbacks. The default is false .

Master

MasterPage

 

Retrieves a reference to the master page for this page. See Chapter 11 for coverage of master pages.

MasterPageFile

string

The filename of the master page.

PreviousPage

Page

 

Retrieves a reference to the previous page.


Figure 6-1. Page class hierarchy



Programming ASP. NET
Programming ASP.NET 3.5
ISBN: 0596529562
EAN: 2147483647
Year: 2003
Pages: 173

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net