Directives for ASP.NET Web Forms

  • Asp.Net Directives


Asp.Net Directives :

Asp.Net Page directives are something that is one of the important   part of every pages. Page directives are instructions, inserted at the top of an Asp.Net page, to control the behavior of the pages.

Syantax  for  Declaring Asp.Net Directive 

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

Trending Now : Advanced Features of Dot Net Framework 

Asp.Net web form page framework supports the following directives

The Application Directive:

Application specific attributes are defined in an application directive . Application directive  is provided at the top of the global.aspx file.

Syntax for Application Directive 

<%@ Application Language=”C#” %>

The Control Directive :

The control Directive is appears in the user control files and it is used with the user controls.

Syntax for Control Directive

<%@ Control Language=”C#”  EnableViewState=”false” %>

The Assembly Directive :

Assembly directive  is used for links an assembly to the page or the application at parse time. Assembly directive  appears  in the global.asax file for application a user control file for linking to a page or user control.

Syntax for Assembly Directive

<%@ Assembly Name =”name” %>

The Implements Directive :

The Implement directive defines to indicates that the master page, web page or user control page must implement the specified dot net framework interface.

syntax for implements directive

<%@ Implements  Interface=”interface_name” %>

The Import Directive :

The Import directive imports a namespace into a web page, user control page of application. The Import directive is specified in the global.asax file, if it is applied to the entire application. If import directive  is in a page of user control page, then it is applied to that page or control.

The basic syntax for import directive 

<%@ namespace=”System.Drawing” %>

The Master Directive :

The Master directive is used  specifies a page file as being the mater page.

 syntax for  MasterPage directive

<%@MasterPageLanguage=”dotnet”AutoEventWireup=”true”  CodeFile=”SiteMater.master.cs” %>

The OutputCache Directive:

The OutputCache directive is used to controls the output caching policies of a web page or a user control.

 syntax for OutputCache directive

<%@ OutputCache Duration=”15″ VaryByParam=”None”  %>

The MasterType Directive :

The MasterType directive  is used to assigns a class name to the Master property of a page, and it is  make to  strongly typed.

 syntax for MasterType directive

<%@ MasterType attribute=”value”[attribute=”value” …]  %>

The Page Directive :

The Page directive  is used to defines the attributes specific to the page file for the page parser and the compiler.

Syntax for Page directive

<%@Page Language=”C#”  AutoEventWireup=”true” CodeFile=”Default.aspx.cs”  Inherits=”_Default”  Trace=”true” %>

The PreviousPageType Directive:

The PreviousPageType directive  is used to assigns a class to a page, so that the page is strongly typed.s

syntax for PreviousPagetype directive

<%@ PreviousPageType attribute=”value”[attribute=”value” …]   %>

The Reference Directive :

The Reference directive is used to  indicates that another page or user control should be compiled and linked to the current page.

syntax of Reference directive

<%@ Reference Page =”somepage.aspx” %>

The Register Directive :

The Register derivative is  registering the custom server controls and user controls.

syntax for  Register directive

<%@ Register Src=”~/footer.ascx” TagName=”footer” TagPrefix=”Tfooter” %>