8.6. Directives


Directives are used to pass optional settings to the ASP.NET pages and compilers. They typically have the following syntax:

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

There are many valid types of directives , which will be described in detail in the following sections. Each directive can have one or more attribute/value pairs , unless otherwise noted. Attribute/value pairs are separated by a space character. Be careful not to have any space characters surrounding the equal sign (=) between the attribute and its value.

Directives are typically located at the top of the appropriate file, although that is not a strict requirement. For example, Application directives are at the top of the global.asax file, and Page directives are at the top of the .aspx files.

8.6.1. Application Directive

The Application directive is used to define application-specific attributes . It is typically the first line in the global.asax file.

Here is a sample Application directive:

     <%@ Application Language="VB" %> 

There are three possible attributes for use in the Application directive, which are outlined in Table 8-4.

Table 8-4. Possible attributes for the Application directive

Attribute

Description

Inherits

The name of the class to inherit from.

Description

Text description of the application. This is ignored by the parser and compiler.

Language

Identifies the language used in any code blocks. Valid values are C#, VB, and VJ#. As other languages adopt support for the .NET Framework, this list will be expanded.


IntelliSense will help you with choosing the enumerated value, as shown in Figure 8-34.

Figure 8-34. Setting the Application Language directive


8.6.2. Assembly Directive

The Assembly directive links an assembly to the application or page at parse time. It is analogous to the /reference: command-line switch used by the VB.NET command-line compilers.

The Assembly directive is contained in either the global.asax file, for application-wide linking, or in a page (.aspx) or user control (.ascx) file, for linking to a specific page or user control. There can be multiple Assembly directives in any file. Each Assembly directive can have multiple attribute/value pairs.

Assemblies located in the \bin subdirectory under the application's virtual root are automatically linked to the application and do not need to be included in an Assembly directive. There are two permissible attributes, listed in Table 8-5 and shown in Figure 8-35.

Table 8-5. Attributes for the Assembly directive

Attribute

Description

Name

The name of the assembly to link to the application or page. Does not include a filename extension. Assemblies usually have a dll extension (they can also have .exe extensions).

Src

Path to a source file to dynamically compile and link.


Figure 8-35. Setting the Assembly directive


Other directives will be covered later in the book as their use becomes relevant.



Programming Visual Basic 2005
Programming Visual Basic 2005
ISBN: 0596009496
EAN: 2147483647
Year: 2006
Pages: 162
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net