The Page Class

All Web forms are instances of the ASP.NET Page class, which is defined in the System.Web.UI namespace. The Page class inherits the TemplateControl class, which in turn, inherits the Control class. As a result, the Page class provides useful events that can be used in the code.

Page Events

ASP.NET uses an event-driven model of programming. This model of ASP.NET defines a sequence of events that are raised during the lifecycle of a Web page. Following are some of the page events:

  • Init - It is the first event that occurs when the server executes an ASP.NET page. It occurs only once in the entire lifecycle of an ASP.NET page.

  • Load - It is fired after the Init event, when the page is requested for the first time and whenever the page is reloaded. This page is used to initialize the variables and the state of controls that are used in the page.

  • Unload - It represents the last event that occurs in the lifecycle of an ASP.NET page. This event is used to perform final cleanup work.

Intrinsic Objects of ASP.NET

ASP.NET has a number of built-in objects that are programmed using methods, properties and collections. These objects are made available to the Page object, which is an instance of the System.Web.UI.Page class from which all ASP.NET pages are inherited.

ASP.NET provides the following built-in objects:

    • Application

    • Request

    • Response

    • Server

    • Session

    • HttpContext

The Application object provides a reference to an object of the HttpApplicationState class. The Application object is used to store information that is defined for the entire Web application.

The Request object provides a reference to an object of the HttpRequest class. The object enables ASP.NET applications to access information sent by the client during a Web request.

The Response object provides a reference to an object of the HttpResponse class. The object enables ASP.NET applications to send information to the client.

The Server object provides a reference to an object of the HttpServerUtility class. The Server object provides methods that can be used to access the methods and properties of the Web server.

The Session object provides a reference to an object of the HttpSessionState class. The Session object enables ASP.NET applications to keep the state of the application as modified or changed by a client.

The HttpContext object holds information about the current HTTP request. A new HTTPContext object is created for every request sent to an ASP.NET application. The new object is created at the beginning of a request and destroyed when the request is completed.