ASP.NET PAGE DIRECTIVE
ASP.NET provides the number of directives with the help of it we can control the behavior of ASP.NET Pages.
We have 11 directives that we can use in our ASP.NET pages or user controls.
We can use these directives regardless we are using Inline Coding Model or Code-Behind Model.
These directives are the commands that complier uses when the page is compiled. Format to write the directive is given below
<%@ Directive attribute= value %>
Now lets talk about the number of directives that are provided in ASP.NET one by one
It specifies the attribute and values that are associated with Web Form Pages (.aspx).When the compiler complies the project the page directive send command that are basically used for compiling the page.
Some of the attributes of the page directive is :- Code File, Buffer, Culture, Debug, Language, Inherits.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>Master Directive
It specifies the attribute and values that are associated with Master Pages (.master).
In it, we specify the properties of the master page (templated page) that we will be conjunction with any number of content page.
Some of the attributes of the master page directive is :- Code File, Debug, Language, Inherits, EnableView State, MasterPageFile, Src.
<%@ Master Language="C#" %>
It is used to bind as ASP.NET user control.
It defines the properties to be inherited by the user control.
When the page is parsed and compiled then these values are assigned then assigned to the use control.
Some of the attributes of the master page directive is :- Code File, Debug, Language, Inherits, EnableView State, Src, ClassName, Description, CompilerOptions
<%@ Control Language="C#" ClassName="WebUserControl" %>
We use the import directive when we want to import any namespace in the ASP.NET page or user control.
When we import any namespace the we are able to use it's classes and interfaces.
This directive has only one attribute called "Namespace".
As much namespace we want to import the same number of import directive must be included.
<%@ Import Namespace="System.Data.SqlClient" %>
When we import any interface the we are able to use it's members.
This directive has only one attribute called "Interface".
As much interface we want to use the same number of implements directive must be included.
<%@ Implements Interface="System.Web.UI.IValidator" %>
When we drag and drop the web user control on the web form page then in the source page the register directive is automatically included.
It is used to register the user control on the page so that the control can be accessed on the web form (.aspx) page.
Some of the attribute of register directive is :- assembly, namespace, src, tagname, tagprefix.
<%@ Register src="WebUserControl.ascx" tagname="WebUserControl" tagprefix="uc1" %>
It associates the assemblies to the ASP.NET page or user control so that at the compile time assembly's classes and interface is available to the page.
Attribute of the register directive is :- name and src
<%@ Assembly Name="Baljeet" Src="Baljeet.cs" %>
It defines the page from which any cross-page posting originate.
It is new in the ASP.NET 3.5.
Attribute of the previouspagetpype is :- typename, virtualpath.MasterType Directive
It is applied on the Web Forms not on WebUserControl.
When we define this directive then we get the references or members contained in the specified master page.
Attribute of the MasterType is :- typename, virtualpath.
<%@ MasterType VirtualPath="~/MasterPage.master" %>
It control the output caching of the ASP.NET pages or user control.
Attribute of the outputcache is :- cacheprofile, duration, location, varybycontrol, varybycustom, shared.
<%@ OutputCache Duration="180" VaryByParam="None" %>
It define the another ASP.NET page or user control that should be complied along with active page or control.
It support only one attribute :- virtualpath.
<%@ Reference VirtualPath="~/WebUserControl.ascx" %>