Using Directives to Modify Web Page Compilation

You can modify web page compilation by including directives. Directives are keywords that are recognized and acted on by the ASP.NET page compiler. They affect a page’s compilation, rather than its presentation. Directives are delimited by the characters <%@ and %> and can appear at any location in the source file (although Microsoft says that “standard practice” is to place them at the top of the file). For example, the following <%@ Page %> directive was shown in Example 6-1, earlier in this chapter:

<%@ Page Language="vb" AutoEventWireup="false" 
   CodeBehind="WebForm1.aspx.vb" Inherits="IdeExamples.WebForm1"%>

Directives are similar in form to HTML tags. There is the directive itself, followed by one or more attributes that specify various settings associated with the directive. A directive without attributes has no effect. Directives are different from HTML tags in that the delimiters are different and in that directives have no closing tags.

ASP.NET defines the following directives and associated attributes:

@ Assembly

Provides a way to reference assemblies defined elsewhere. This directive’s attributes are:

Name

Specifies the name of an assembly in the global assembly cache. For example:

<%@ Assembly Name="System.Windows.Forms" %>
SRC

Specifies the path of a Visual Basic .NET source file to be compiled and referenced. The path is relative to the web application’s virtual folder. For example:

<%@ Assembly SRC="SomeClass.vb" ...

Get Programming Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.