Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [95]

By Root 5413 0
values that can be rendered to a particular .NET Framework type, specific to the attribute. When the ASP.NET page is parsed, all the directive attributes are extracted and stored in a dictionary. The names and number of attributes must match the expected schema for the directive. The string that expresses the value of an attribute is valid as long as it can be converted into the expected type. For example, if the attribute is designed to take a Boolean value, true and false are its only feasible values.

The @Page Directive


The @Page directive can be used only in .aspx pages and generates a compile error if used with other types of ASP.NET files such as controls and Web services. Each .aspx file is allowed to include at most one @Page directive. Although not strictly necessary from the syntax point of view, the directive is realistically required by all pages of some complexity.

@Page features over 40 attributes that can be logically grouped in three categories: compilation (defined in Table 5-4), overall page behavior (defined in Table 5-5), and page output (defined in Table 5-6). Each ASP.NET page is compiled upon first request, and the HTML actually served to the browser is generated by the methods of the dynamically generated class. The attributes listed in Table 5-4 let you fine-tune parameters for the compiler and choose the language to use.

Table 5-4. @Page Attributes for Page Compilation

Attribute

Description

ClassName

Specifies the name of the class that will be dynamically compiled when the page is requested. It must be a class name without namespace information.

CodeFile

Indicates the path to the code-behind class for the current page. The source class file must be deployed to the Web server.

CodeBehind

Attribute consumed by Visual Studio, indicates the path to the code-behind class for the current page. The source class file will be compiled to a deployable assembly.

CodeFileBaseClass

Specifies the type name of a base class for a page and its associated code-behind class. The attribute is optional, but when it is used the CodeFile attribute must also be present.

CompilationMode

Indicates whether the page should be compiled at run time.

CompilerOptions

A sequence of compiler command-line switches used to compile the page.

Debug

A Boolean value that indicates whether the page should be compiled with debug symbols.

Explicit

A Boolean value that determines whether the page is compiled with the Visual Basic Option Explicit mode set to On. Option Explicit forces the programmer to explicitly declare all variables. The attribute is ignored if the page language is not Visual Basic .NET.

Inherits

Defines the base class for the page to inherit. It can be any class derived from the Page class.

Language

Indicates the language to use when compiling inline code blocks ( <% … %>) and all the code that appears in the page