Monday, 9 April 2012

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"  %>


  1. Great informative site. I'm really impressed after reading this blog post. I really appreciate the time and effort you spend to shareLo0k here this with us! I do hope to read more updates from you.

  2. look... information and cute writing style.This is a cool read ..

  3. I would be very thankful if you continue with quality what you are serving right now with your blog... really enjoyed it...and i really appreciate to you for this....its always pleasure to read so....Thanks for sharing!!!=)

  4. On all free people conducted єto very good internet advertising.

  5. Just so you can make a day of hard work.