Monday, May 26, 2008

ASP.NET 2.0 Directives


Today I've decided to write about ASP.NET 2.0 directives. There are 11 of them. Here is a full list of directives:

DirectiveAttributesShort description
Imports assembly with given name into page or control
@ControlThe same as Page hasApplied for properties setting while creating custom controls
@ImplementsInterfaceSpecifies that page's class implements this interface
@ImportNamespaceImports given namespace
@MasterThe same as Page hasApllied for specifying Master Page template. New in ASP.NET 2.0
Gives strongly typed reference on class contained in Master Page. Gives opportunity to reference class properties.
Controls Page or Control caching. See msdn for details.
@PageDescribed belowAttributes refering current Page.Used only if files with .aspx extension.
Page, which was used for user data sending. New in ASP.NET 2.0.
Page or Control that should be compiled with current.
Associates aliases with namespaces and class names for notation in custom server control syntax.

@Page Directive

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.

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

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.

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

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

Culture: Specifies the culture setting of the page. If you set to auto, enables the page to automatically detect the culture required for the page.

UICulture: Specifies the UI culture setting to use for the page. Supports any valid UI culture value.

ValidateRequest: Indicates whether request validation should occur. If set to true, request validation checks all input data against a hard-coded list of potentially dangerous values. If a match occurs, an HttpRequestValidationException Class is thrown. The default is true. This feature is enabled in the machine configuration file (Machine.config). You can disable it in your application configuration file (Web.config) or on the page by setting this attribute to false.

Theme: To specify the theme for the page. This is a new feature available in Asp.Net 2.0.

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.

MasterPageFile: Specify the location of the MasterPage file to be used with the current Asp.Net page.

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

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

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

There are also other attributes which are of seldom use such as Buffer, CodePage, ClassName, EnableSessionState, Debug, Description, EnableTheming, EnableViewStateMac, TraceMode, WarningLevel, etc. Here is an example of how a @Page directive looks

No comments: