Professional VB 2005 with .NET 3.0 (Programmer to Programmer)

ASP.NET directives are part of every ASP.NET page. You can control the behavior of your ASP.NET pages by using these directives. Here is an example of the Page directive:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

Eleven directives are at your disposal in your ASP.NET pages or user controls. You use these directives in your applications whether the page uses the code-behind model or the inline coding model.

Basically, these directives are commands that the compiler uses when the page is compiled. Directives are simple to incorporate into your pages. A directive is written in the following format:

<%@ [Directive] [Attribute=Value] %>

A directive is opened with <%@ and closed with %>. It is best to put these directives at the top of your pages or controls because this is traditionally where developers expect to see them (although the page still compiles if the directives are located elsewhere. Of course, you can also add more than a single attribute to your directive statements, as shown here:

<%@ [Directive] [Attribute=Value] [Attribute=Value] %>

The following table describes the directives at your disposal in ASP.NET 2.0:

Open table as spreadsheet

Directive

Description

Assembly

Links an assembly to the page or user control to which it is associated

Control

Page directive meant for use with user controls (.ascx)

Implements

Implements a specified .NET Framework interface

Import

Imports specified namespaces into the page or user control

Master

Enables you to specify a master page - specific attributes and values to use when the page parses or compiles. This directive can be used only with master pages (.master).

MasterType

Associates a class name to a page in order to get at strongly typed references or members contained within the specified master page

OutputCache

Controls the output caching policies of a page or user control

Page

Enables you to define page-specific attributes and values to use when the page parses or compiles. This directive can be used only with ASP.NET pages (.aspx).

PreviousPageType

Enables an ASP.NET page to work with a postback from another page in the application

Reference

Links a page or user control to the current page or user control

Register

Associates aliases with namespaces and class names for notation in custom server control syntax

Категории