Page Directive in ASP.NET

The @Page directive enables you to specify attributes and values for an ASP.NET Page to be used when the page is parsed and compiled. Every .aspx files should include this @Page directive to execute. There are many attributes belong to this directive. We shall discuss some of the important attributes here.

1. Language: This attribute tells the compiler about the language being used in the code-behind. Values can represent any .NET-supported language, including Visual Basic, C#, or JScript or Delphi.

2. AutoEventWireup: For every page there is an automatic way to bind the events to methods in the same .aspx file or in code behind. The default value is true.

3. CodeFile: Specifies the code-behind file with which the page is associated.


4. Title:  To set the page title other than what is specified in the master page.

5. Theme: To specify the theme for the page. Just give the address of the theme page.

6. SmartNavigation: Indicates the smart navigation feature of the page. When set to True, this returns the postback to current position of the page. The default value is false.

7. MasterPageFile: Specify the location of the MasterPage file to be used with the current ASP.NET page.

8. EnableViewState: Indicates whether view state is maintained across page requests. True if view state is maintained; otherwise, false. The default is true.

9. ErrorPage: Specifies a target URL for redirection if an unhandled page exception occurs.

10. Inherits: Specifies a code-behind class for the page to inherit. This can be any class derived from the Page class.

11. Debug: To debug the page. While development, we keep it true and while deployment we make it false. Default is false.

There are also other attributes which are of seldom use such as Buffer, CodePage, ClassName, EnableSessionState, Description, EnableTheming, EnableViewStateMac, TraceMode, WarningLevel, etc.

Here is an example of how a @Page directive looks

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sample.aspx.cs" Inherits="Sample" Title="Sample Page Title"  %>