ASP.NET directives are instructions for specifying optional settings, such as registering a custom control and the language of the page. These settings describe how the NET Framework handles single-page form (.aspx) or user control (.ascx) web pages.
Basic syntax for issuing commands:
<%@ directive_name attribute=value [attribute=value] %>
In this section, we'll introduce ASP.NET directives, most of which will be used throughout the tutorial.
Application directives define application-specific properties. It is provided at the top of the global.aspx file.
Basic syntax of application instructions:
<%@ Application Language="C#" %>
Properties of the application directive:
property | describe |
---|---|
Inherits | Inherited from the name of the class. |
Description | A text description of the application. The parser and compiler ignore this. |
Language | The language used in the code group. |
Collection directives link components to a web page or application during analysis. This may occur throughout the application type link in a Global.asax file, in a page file, in a user control that links to another web page, or in a user control.
The basic syntax of a collection control is:
<%@ Assembly Name ="myassembly" %>
The properties of the collection control are:
property | describe |
---|---|
Name | The name of the linked collection component. |
Src | The path to which source files are dynamically linked and edited. |
Control instructions are used with user controls and appear in user control (.ascx) files.
The basic syntax of control instructions is:
<%@ Control Language="C#" EnableViewState="false" %>
The properties of the control instructions are:
property | describe |
---|---|
AutoEventWireup | Boolean value that allows or disables automatic association of event handlers. |
ClassName | The file name of the control. |
Debug | Boolean value that allows or disables editing debugging symbols. |
Description | Text description of the control page, ignored by the compiler. |
EnableViewState | The page request is a Boolean value of whether to maintain the view state. |
Explicit | In VB language, tells the editor to use option display mode. |
Inherits | Control the class inherited by the page. |
Language | Coding and scripting languages. |
Src | The filename of the code-behind class. |
Strict | In the VB language, tells the editor to use the option Standard Mode. |
Tool directives indicate that a web page, master page, or user control page must implement a specified .Net Framework interface.
The basic syntax of tool instructions is:
<%@ Implements Interface="interface_name" %>
The import directive imports a namespace into a page of a user-controlled application. If the Import directive is specified in the global.asax file, it applies to the entire application. If it is in a web page within a user-controlled page, it will be applied to that web page or control.
The basic syntax of the import directive is:
<%@ namespace="System.Drawing" %>
The main directive specifies a page file as the home page.
The basic syntax of the sample home page directive is:
<%@ MasterPage Language="C#" AutoEventWireup="true" CodeFile="SiteMater.master.cs" Inherits="SiteMaster" %>
The MasterType directive assigns a class name to the page's master attribute, reinforcing its type.
The basic syntax of the master directive is:
<%@ MasterType attribute="value"[attribute="value" ...] %>
The output caching directive controls the output caching policy of a web page or user control.
Basic syntax for output caching instructions:
<%@ OutputCache Duration="15" VaryByParam="None" %>
Page directives define page file attributes for specific page parsers and compilers.
The basic syntax of the page directive is:
%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Trace="true" %>
The properties of the page directive are:
property | describe |
---|---|
AutoEventWireup | Boolean value that allows or disables page events being automatically bound to methods; for example, Page_Load. |
Buffer | Boolean value that allows or disables HTTP response buffering. |
ClassName | The category name of the page. |
ClientTarget | The server control should render content to the browser |
CodeFile | The name of the code-behind file. |
Debug | Boolean value that allows or disables compilation with debug symbols. |
Description | The file description of the page, ignored by the parser. |
EnableSessionState | Enables or disables page session status as read-only. |
EnableViewState | A Boolean value that allows or disallows cross-page requests for view state. |
ErrorPage | Redirect address in case of unhandled page exception. |
Inherits | The name of the code-behind or other class. |
Language | Code programming language. |
Src | The filename of the code-behind class. |
Trace | Enable or disable tracking. |
TraceMode | Indicates how tracking information is displayed and sorted by time or category. |
Transaction | Indicates whether the transaction is supported. |
ValidateRequest | A Boolean value indicating whether all input data is validly verified as a hardcoded list. |
The previous page directive assigns a category to a page, causing that page type to be enhanced.
Basic syntax for a sample of the previous page directive:
<%@ PreviousPageType attribute="value"[attribute="value" ...] %>
The reference directive indicates that another page or user control should be compiled and linked to the current page.
The basic syntax of the reference directive is:
<%@ Reference Page ="somepage.aspx" %>
The registration directive is used to register custom server controls and user controls.
The basic syntax of the registration directive is:
<%@ Register Src="~/footer.ascx" TagName="footer" TagPrefix="Tfooter" %>