To know the Directives used in ASP.NET page, First of all, we should know what is ASP.NET directive and where it is used?
So, Directive are the commands helps in specifying optional settings, such as registering a custom control and page language. These settings describe how the web forms (.aspx) or user controls (.ascx) pages are processed by the .Net framework.
The syntax for declaring a directive is:
<%@ directive_name attribute=value [attribute=value] %>
Following are the directives used in ASP.NET :
1. @Page : To specify the attributes for an ASP.NET page @Page Directive is used.
Syntax :
<%@Page Language="C#" AutoEventWIreup="false" CodeFile="Default.aspx.cs" Inherits="_Default"%>
2. @Master : @master directive is for Master pages where we need to define template page's property and allows content page to receive all the properties defined in the Master Page.
Syntax :
<%@ MasterPage Language="C#" AutoEventWireup="true" CodeFile="SiteMater.master.cs" Inherits="SiteMaster" %>
3. @MasterType : The @MasterType Directive is used getting strongly typed references or members contained in the specified Master Page. This directive supports the two attributes: Typename and virtualpath. Typename sets the name of the derived class from which to get the strongly typed or reference members and virtualpath sets the location of the page from which these are retrieved.
syntax:
<%@ MasterType attribute="value"[attribute="value" ...] %>
4. @Control : It is used to create user controls.
Syntax :
<%@ Control Language="C#" EnableViewState="false" %>
5. @Import : It is used to import namespace into a web page, user control page of application.
syntax:
<%@ namespace="System.data" %>
6. @Implements : It is used to implement a specified .NET framework interface.
syntax :
<%@ Implements Interface=System.Web.UI.IValidator %>
7. @Register : This directive registers your user control on the page so that the control can be accessed by the page.
syntax :
<%@ Register TagPrefix="MayTag Namespace="MyName.MyNameSpace" Assembly="MyAssembly"%>
7. @Assembly : It used to make your ASP.NET page aware of external components. This directive supports two attributes:
a. Name: Enables you specify the name of an assembly you want to attach to the page. (There is no need to mention the extension for file name.)
b. Src: It represents the name of a source code file.
Syntax:
<%@Assembly Name="MyAssembly"%>
<%@Assembly src="MYAssembly.cs">
8. @output cache : It controls the output caching policies of an ASP.NET page. It has two attributes:
a. Duration: The duration of time in seconds that the page or user control is cached.
Syntax :
<%@ OutputCache Duration ="160" VaryByParam="None"%>
@Previouspagetype
b. Location:
- To specify the location to store the output cache.
- To store the output cache on the browser client where the request originated set the value as ‘Client’.
- To store the output cache on the Web server, mention the location as Server.
Syntax :
<%@ OutputCache Location="None" VaryByParam="None" %>
9. @Reference : This directive declares that another page or user control should be complied along with the active page or control. It sets the location of the page or user control from which the active page will be referenced.
Syntax :
<%@Reference VirtualPayh="~/MyControl.ascx"%>
0 Comment(s)