{"id":84,"date":"2014-05-20T14:59:00","date_gmt":"2014-05-20T13:59:00","guid":{"rendered":"https:\/\/debuggersspace.com\/index.php\/2014\/05\/20\/what-is-the-asp-net-page-directives\/"},"modified":"2014-05-20T14:59:00","modified_gmt":"2014-05-20T13:59:00","slug":"what-is-the-asp-net-page-directives","status":"publish","type":"post","link":"https:\/\/debuggersspace.com\/index.php\/2014\/05\/20\/what-is-the-asp-net-page-directives\/","title":{"rendered":"What is the ASP.Net Page Directives?"},"content":{"rendered":"<div class='booster-block booster-read-block'>\n                <div class=\"twp-read-time\">\n                \t<i class=\"booster-icon twp-clock\"><\/i> <span>Read Time:<\/span>3 Minute, 51 Second                <\/div>\n\n            <\/div><div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"background-color: white; color: #333333; outline: none 0px;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\"><span style=\"outline: none 0px;\"><b style=\"outline: none 0px;\">What is a Page Directive?<\/b><br style=\"outline: none 0px;\" \/><br \/>&#8211;<span style=\"color: black; text-align: justify;\">ASP.Net directives are instructions<\/span><\/span>&nbsp;or&nbsp;commands<span style=\"color: black; text-align: justify;\">&nbsp;to specify 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.<\/span><\/span><\/div>\n<div style=\"background-color: white; color: #333333; outline: none 0px;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\"><span style=\"outline: none 0px;\">-These commands or<\/span><span style=\"background-color: transparent; outline: none 0px;\"><span style=\"color: black; text-align: justify;\">&nbsp;instructions<\/span><\/span><span style=\"background-color: transparent;\">&nbsp;<\/span>are used by the compiler when the page is compiled.<\/span><\/div>\n<div style=\"background-color: white; color: #333333; outline: none 0px;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\"><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">How to use the directives in an ASP.NET page<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>It is not difficult to add a directive to an ASP.NET page. It is simple to add directives to an ASP.NET page. You can write directives in the following format:<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>&lt;%@[Directive][Attributes]%&gt;<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>See the directive format, it starts with &#8220;&lt;%@&#8221; and ends with &#8220;%&gt;&#8221;. The best way is to put the directive at the top of your page. But you can&nbsp;put a directive anywhere in a page. One more thing, you can put more than one attribute in a single directive.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Here is the full list of directives:<\/span><\/div>\n<ul style=\"background-color: white; color: #333333; outline: none 0px;\">\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@Page<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@Master<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@Control<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@Import<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@Implements<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@Register<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@Assembly<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@MasterType<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@Output Cache<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@PreviousPageType<\/span><\/li>\n<li style=\"outline: none 0px;\"><span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\">@Reference<\/span><\/li>\n<\/ul>\n<div style=\"background-color: white; color: #333333; outline: none 0px;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif; outline: none 0px;\"><b style=\"outline: none 0px;\">@Page<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>When you want to specify the attributes for an ASP.NET page then you need to use @Page Directive. As you know, an ASP.NET page is a very important part of ASP.NET, so this directive is commonly used in ASP.NET.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@Page Language=&#8221;C#&#8221; AutoEventWIreup=&#8221;false&#8221; CodeFile=&#8221;Default.aspx.cs&#8221; Inherits=&#8221;_Default&#8221;%&gt;<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">@Master<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Now you have some information about @Page Directives. The @Master Directive is quite similar to the @Page Directive. The only difference is that the @master directive is for Master pages. You need to note that, while using the @Master Directive you define the template page&#8217;s property. Then any content page can inherit all the properties defined in the Master Page. But there are some properties that are only available in a Master Page.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@Master Language=&#8221;C#&#8221; AutoEventWIreup=&#8221;false&#8221; CodeFile=&#8221;MasterPage1.master.cs&#8221; Inherits=&#8221;MasterPage&#8221;%&gt;<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">@Control&nbsp;<\/b><br style=\"outline: none 0px;\" \/>@Control builds ASP.NET user controls. When you use the directive you define the properties to be inherited by the user controls and theses values are assigned to the user controls<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@Control Language=&#8221;C#&#8221; Explicit=&#8221;True&#8221; CodeFile=&#8221;WebUserControl.ascx.cs&#8221; Inherits=&#8221;WebUserControl&#8221; %&gt;<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">@Import&nbsp;<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>As you know you need to define namespaces in your .cs class before using&nbsp;a C# or VB class. So the @Import Directive imports namespaces. This directive supports just a single attribute &#8220;namespace&#8221; and this attribute takes a string value that specifies the namespace to be imported. One thing you need to note is that the @Import Directive cannot contain more than one attribute\/value pair. But you can&nbsp;use multiple lines.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@Import Namespace=&#8221;System.Data&#8221;%&gt;<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">@Implements&nbsp;<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>The @Implements Directive gets the ASP.NET pages to implement .Net framework interfaces. This directive only supports a single attribute interface.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@Implements Interface=&#8221;System.Web.UI.IValidator&#8221;%&gt;<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">@Register&nbsp;<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>When you create a user control and you drag that user control onto your page then you will see the @Register directive. This directive registers your user control on the page so that the control can be accessed by the page.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@ Register TagPrefix=&#8221;MayTag Namespace=&#8221;MyName.MyNameSpace&#8221; Assembly=&#8221;MyAssembly&#8221;%&gt;<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">@Assembly&nbsp;<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>The @Assembly Directive attaches assemblies to the page or an ASP.NET user control thereby all the assembly classes and interfaces are available to the class. This directive supports the two attributes Name and src. The Name attribute defines the assembly name and the src attribute defines the source of the assembly.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@Assembly Name=&#8221;MyAssembly&#8221;%&gt;<br style=\"outline: none 0px;\" \/>&lt;%@Assembly src=&#8221;MYAssembly.cs&#8221;&gt;<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">@MasterType&nbsp;<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>The @MasterType Directive connects a class name&nbsp;to the ASP.NET page for 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.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@MasterType VirtualPath=&#8221;\/MasterPage1.master&#8221;%&gt;<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">@output cache<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>It controls the output caching policies of an ASP.NET page.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@ OutputCache Duration =&#8221;180&#8243; VaryByParam=&#8221;None&#8221;%&gt;<br style=\"outline: none 0px;\" \/>@Previouspagetype<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>This directive specifies the page from which any cross-page posting originates.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/><b style=\"outline: none 0px;\">@Reference<\/b><br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>This directive declares that another page or user control shout be complied along with the active page or control. This directive supports the single attribute virtualpath. It sets the location of the page or user control from which the active page will be referenced.<br style=\"outline: none 0px;\" \/><br style=\"outline: none 0px;\" \/>Example:&nbsp;&lt;%@Reference VirtualPayh=&#8221;~\/MyControl.ascx&#8221;%&gt;<\/span><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>What is a Page Directive?&#8211;ASP.Net directives are instructions&nbsp;or&nbsp;commands&nbsp;to specify 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. -These commands or&nbsp;instructions&nbsp;are used by the compiler when the page is compiled. How to use the [&hellip;]<\/p>\n","protected":false},"author":43,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[23],"tags":[],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-asp-net"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Himanshu Namdeo","author_link":"https:\/\/debuggersspace.com\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"What is a Page Directive?&#8211;ASP.Net directives are instructions&nbsp;or&nbsp;commands&nbsp;to specify 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. -These commands or&nbsp;instructions&nbsp;are used by the compiler when the page is compiled. How to use the&hellip;","_links":{"self":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/84"}],"collection":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/users\/43"}],"replies":[{"embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":0,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"wp:attachment":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}