Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [101]

By Root 5313 0
a new virtual namespace in which all child controls are guaranteed to have unique names in the overall tree of controls. (This is a very important feature for iterative data-bound controls, such as DataGrid, and for user controls.)

The Page class also implements the methods of the IHttpHandler interface, thus qualifying it as the handler of a particular type of HTTP requests—those for .aspx files. The key element of the IHttpHandler interface is the ProcessRequest method, which is the method the ASP.NET runtime calls to start the page processing that will actually serve the request.

Note

INamingContainer is a marker interface that has no methods. Its presence alone, though, forces the ASP.NET runtime to create an additional namespace for naming the child controls of the page (or the control) that implements it. The Page class is the naming container of all the page’s controls, with the clear exception of those controls that implement the INamingContainer interface themselves or are children of controls that implement the interface.

Properties of the Page Class


The properties of the Page class can be classified in three distinct groups: intrinsic objects, worker properties, and page-specific properties. The tables in the following sections enumerate and describe them.

Intrinsic Objects


Table 5-8 lists all properties that return a helper object that is intrinsic to the page. In other words, objects listed here are all essential parts of the infrastructure that allows for the page execution.

Table 5-8. ASP.NET Intrinsic Objects in the Page Class

Property

Description

Application

Instance of the HttpApplicationState class; represents the state of the application. It is functionally equivalent to the ASP intrinsic Application object.

Cache

Instance of the Cache class; implements the cache for an ASP.NET application. More efficient and powerful than Application, it supports item priority and expiration.

Profile

Instance of the ProfileCommon class; represents the user-specific set of data associated with the request.

Request

Instance of the HttpRequest class; represents the current HTTP request.

Response

Instance of the HttpResponse class; sends HTTP response data to the client.

RouteData

Instance of the RouteData class; groups information about the selected route (if any) and its values and tokens. (Routing in Web Forms is covered in Chapter 4, “xxx.”) The object is supported only in ASP.NET 4.

Server

Instance of the HttpServerUtility class; provides helper methods for processing Web requests.

Session

Instance of the HttpSessionState class; manages user-specific data.

Trace

Instance of the TraceContext class; performs tracing on the page.

User

An IPrincipal object that represents the user making the request.

I’ll cover Request, Response, and Server in Chapter 16; Application and Session are covered in Chapter 17; Cache will be the subject of Chapter 19. Finally, User and security will be the subject of Chapter 19.

Worker Properties


Table 5-9 details page properties that are both informative and provide the foundation for functional capabilities. You can hardly write code in the page without most of these properties.

Table 5-9. Worker Properties of the Page Class

Property

Description

AutoPostBackControl

Gets a reference to the control within the page that caused the postback event.

ClientScript

Gets a ClientScriptManager object that contains the client script used on the page.

Controls

Returns the collection of all the child controls contained in the current page.

ErrorPage

Gets or sets the error page to which the requesting browser is redirected in case of an unhandled page exception.

Form

Returns the current HtmlForm object for the page.

Header

Returns a reference to the object that represents the page’s header. The object implements IPageHeader.

IsAsync

Indicates whether the page is being invoked through an asynchronous handler.

IsCallback

Indicates whether the page is being loaded in response to a client script callback.

Return Main Page Previous Page Next Page

®Online Book Reader