ASP.NET Architecture, Part 1 - ASP.NET Page Class
(Page 5 of 8 )
ASP.NET pages begin as code in a text file with an .aspx extension. They lie within an Internet Information Service (IIS) virtual directory located somewhere on your LAN or on a remote server. Pages are instantiation classes derived from the parent Page class. For example, you can write your code using any text editor such as Notepad or, preferably, Visual Studio .NET. The text file becomes a valid ASP.NET page only when a client sends a request to the server to render the page to the client browser. The page compiles to a class. It is created at runtime as a Page object and is subsequently cached in memory. It naturally follows that the Page object serves as a naming container for all server controls embedded within the page. The only exception to this is those server controls implementing the INamingContainer interface. Examining the Page Class
ASP.NET functionality lies primarily with the Page class. Every page derives from the Page class, thereby inheriting all the methods and properties the Page class exposes. The following list describes several members of this class.
- The ASP objects such as Application, Session, Request, Response, Server, and Context are implemented in ASP.NET as class instances, which are exposed as properties of a specified page.
- The Controls collection provides access to the set of controls defined for a specific page. With this collection, you can add or alter controls.
- The IsPostBack property is used to determine whether the current request is a GET request or a POST request.
- The User property provides information about the logged-in user.
- The Cache property enables access to the ASP.NET cache engine. You can use this property to allow data to be cached for later retrieval.
- The FindControl property allows you to locate a control in the Controls collection by specifying the ID attribute property.
- The ViewState property allows you to store a page’s state in a hidden form field (key-value pair) between client requests.
- The ClearChildViewState property allows you to delete view state information for any child controls residing on a page.
Two methods exist for inheriting from the Page class: the first is adding the @ Page directive to an .aspx file. By doing so, the directive automatically makes available all page properties and methods for any code written on the page.
<%@ Page Language ="vb"%>
The second method uses the code-behind feature to inherit from the Page class associated with a particular page by specifying either the Src or Inherits attribute:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="RegisterForm.aspx.vb"
Inherits="RegisterForm.WebForm1" %>
The second method allows ASP.NET to combine the code in the web form’s .aspx file with the code in the code-behind class file and compile both files to a single merged file at compile time.
Come back this Friday, 27/02/2004, for part two of ASP.NET Architecture. This is chapter six of .NET & J2EE Interoperability, by Dwight Peltzer (McGraw-Hill/Osborne, ISBN 0-07-223054-1, 2004). Buy this book now.
|
Next: An ASP.NET Page's Life Cycle >>
More ASP.NET Articles
More By McGraw-Hill/Osborne