ASP.NET - Directives

ASP.NET directives are instructions to specify optional settings, such as registering a custom control and page language. These settings describe how the web forms (.aspx) or user controls (.ascx) pages are processed by the .Net framework.

The syntax for declaring a directive is:

<%@ directive_name attribute=value [attribute=value] %>

In this section, we will just introduce the ASP.NET directives and we will use most of these directives throughout the tutorials.

The Application Directive

The Application directive defines application-specific attributes. It is provided at the top of the global.aspx file.

The basic syntax of Application directive is:

<%@ Application Language="C#" %>

The attributes of the Application directive are:

Attributes

Description

Inherits

The name of the class from which to inherit.

Description

The text description of the application. Parsers and compilers ignore this.

Language

The language used in code blocks.

The Assembly Directive

The Assembly directive links an assembly to the page or the application at parse time. This could appear either in the global.asax file for application-wide linking, in the page file, a user control file for linking to a page or user control.

The basic syntax of Assembly directive is:

<%@ Assembly Name ="myassembly" %>

The attributes of the Assembly directive are:

Attributes

Description

Name

The name of the assembly to be linked.

Src

The path to the source file to be linked and compiled dynamically.

The Control Directive

The control directive is used with the user controls and appears in the user control (.ascx) files.

The basic syntax of Control directive is:

<%@ Control Language="C#" EnableViewState="false" %>

The attributes of the Control directive are:

Attributes

Description

AutoEventWireup

The Boolean value that enables or disables automatic association of events to handlers.

ClassName

The file name for the control.

Debug

The Boolean value that enables or disables compiling with debug symbols.

Description

The text description of the control page, ignored by compiler.

EnableViewState

The Boolean value that indicates whether view state is maintained across page requests.

Explicit

For VB language, tells the compiler to use option explicit mode.

Inherits

The class from which the control page inherits.

Language

The language for code and script.

Src

The filename for the code-behind class.

Strict

For VB language, tells the compiler to use the option strict mode.

The Implements Directive

The Implement directive indicates that the web page, master page or user control page must implement the specified .Net framework interface.

The basic syntax for implements directive is:

<%@ Implements Interface="interface_name" %>

The Import Directive

The Import directive imports a namespace into a web page, user control page of application. If the Import directive is specified in the global.asax file, then it is applied to the entire application. If it is in a page of user control page, then it is applied to that page or control.