This documentation is archived and is not being maintained.

Page Class

Represents an .aspx file, also known as a Web Forms page, requested from a server that hosts an ASP.NET Web application.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Page : public TemplateControl, 

The Page class is associated with files that have an .aspx extension. These files are compiled at run time as Page objects and cached in server memory.

If you want to create a Web Forms page using the code-behind technique, derive from this class. Rapid application development (RAD) designers, such as Microsoft Visual Studio, automatically use this model to create Web Forms pages.

The Page object serves as the naming container for all server controls in a page, except those that implement the INamingContainer interface or are child controls of controls that implement this interface.

The Page class is a control that acts as the user interface for your Web application, and as such should be scrutinized to make sure best practices for writing secure code and securing applications are followed. For general information on these topics, see Overview of Web Application Security Threats, Security Policy Best Practices, and Key Security Concepts. For more specific information, see Securing Standard Controls, How to: Display Safe Error Messages, How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Introduction to the Validation Controls.

The following code example demonstrates how the Page class is used in the code-behind page model. Note that the code-behind source file declares a partial class that inherits from a base page class. The base page class can be Page, or it can be another class that derives from Page. Furthermore, note that the partial class allows the code-behind file to use controls defined on the page without the need to define them as field members.

No code example is currently available or this language may not be supported.

The following code example shows the .aspx file that corresponds to the preceding code-behind source file.

Security noteSecurity Note:

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

No code example is currently available or this language may not be supported.

You must use the @ Page directive and use the Inherits and CodeFile attributes to link the code-behind file to the .aspx file. In this example, the Inherits attribute indicates the MyCodeBehind class and the CodeFile attribute indicates the path to the language-specific file that contains the class.

The following code example demonstrates the single-file page model and how to access the IsPostBack property and the Response property of the Page.

No code example is currently available or this language may not be supported.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0