The ASP.NET Architecture

One of the aspects of ASP.NET that makes it so powerful is that it is object-oriented and makes object and component programming easy. As mentioned in previous sections, a C#Builder ASP.NET application consists of a Web Form and a code-behind file. For these to work together, there must be some relationship between these files. Additionally, there must be some relationship between the code in these files and the rest of the ASP.NET infrastructure. These relationships do exist via inheritance, as illustrated in Figure 11.6.

Figure 11.6. ASP.NET Web page architecture.

graphics/11fig06.gif

The Web Form, WebForm1.aspx, at the bottom of Figure 11.6 inherits the code-behind file, WebForm1.aspx.cs. The mechanism that makes this possible is the Inherits attribute of the Page directive, shown following:

 <%@ Page language="c#" Debug="true" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="SimpleWebPage.WebForm1" %> 

In the Page directive, the code-behind file is named WebForm1.aspx.cs and is identified by the Codebehind attribute. The Inherits attribute identifies the fully qualified type of the class in the code-behind file. It is in the SimpleWebPage namespace, with a class name of WebForm1.

Whenever a control is dragged from the Tool Palette and dropped onto the designer surface, a tag is added to the Web Form code. At the same time, a type declaration for that control is added to the WebForm1 class in the code-behind file. This way, both the Web Form and code-behind can access that control as a normal C# object.

As illustrated in Figure 11.6, the WebForm1 class in the code-behind file inherits from the Page class. A snippet of the code is shown following:

 namespace SimpleWebPage {    /// <summary>    /// Summary description for WebForm1.    /// </summary>    public class WebForm1 : System.Web.UI.Page    { 

The Page class contains functionality that enables the Web Form and code-behind file to access ASP.NET functionality. For instance, the Request object enables access to the caller's HTTP information sent when a request was made. Along the same lines, the Response object contains information that will be returned to the caller's browser. Table 11.3 identifies available properties of the Page class and what they are for.

Table 11.3. Page Class Properties

NAME

PURPOSE

Application

Object for maintaining application-wide state. Discussed in more detail in Chapter 12.

Cache

Configurable cache for storing objects for a specified amount of time or until a certain event.

ClientTarget

Controls page rendering for a given browser.

EnableViewState

View state is Web Form information shuttled between client browser and server. It is enabled by default, but setting this to false will disable it.

ErrorPage

The Web page to redirect to for unhandled exceptions.

ID

Identifier associated with the Page class instance.

IsPostBack

Used in the Page_Load event to determine whether the page has been posted back. A postback occurs when the user resubmits the same page they are working on. This is the recommended way of handling user input on a page in ASP.NET. On the first request for a page, IsPostBack will be false, but will be true on subsequent postbacks.

IsValid

ASP.NET has validation controls that perform both client-side and server validation for user input controls. IsValid will return true if all validation controls pass.

Request

Contains all HTTP information from the user's browser.

Response

Contains all HTTP information returned to user's browser.

Server

Holds a set of utilities for working with the Web page. That is, Server.MapPath(".") obtains the current physical directory that the Web page is executed from.

Session

Maintains state for per-user session. Discussed in more detail in Chapter 12.

SmartNavigation

Enables smart navigation for Internet Explorer v5.5 browsers and higher. Smart navigation repositions a Web page to where the user was working when the page is reloaded.

Trace

Supports debugging a Web page when the Trace attribute of the Web page is set to true. For example: Trace.Write("Some diagnostic message.").

User

Obtains information about the user making a page request.

Validators

A collection of all validator controls on the Web page.

ViewStateUserKey

Identifier of a user in the view state.

Visible

Controls whether the page is hidden or shown.



C# Builder KickStart
C# Builder KickStart
ISBN: 672325896
EAN: N/A
Year: 2003
Pages: 165

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