What is a Page Directive in .NET
I'm studying up for a Microsoft Certification exam, and some of the wording for the 'content' in the examn confused me. In the MS exam website, under Developing Web Form Pages, it says in regard to the content on the exam...
This objective may include but is not limited to: page directives such as ViewState, request validation, event validation, MasterPageFile; ClientIDMode;
I was under the impression that a page directive referred to the @Page keyword, and the associated values defined in t开发者_StackOverflow社区he @Page section were attributes/properties. But the wording of the exam content almost implies that the attributes/properties of the @Page keyword are directives.
Could someone please clear this up for me?
I think their verbiage is a little confusing. You are correct that the values within the directive are essentially properties. In fact, you can set most of these AS properties within the object model (e.g. in the codebehind).
protected override void OnInit( EventArgs e )
{
this.EnableViewState = true;
this.MasterPageFile = "~/something.master";
this.Title = "Hello World";
}
Their are several important directives besides Page
, such as Import
and Control
. I would suggest being familiar with these as well.
EDIT: I was curious where these attributes end up when set from the Page directive, so I took a look at the ASP.Net cache. As you probably know, when a page is executed it is turned into an object and cached on the file system in:
c:\windows\Microsoft.Net\Framework[version]\Temporary ASP.Net Files\
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
private void @__BuildControlTree(content_shared_toolbarcontrol_ascx @__ctrl) {
System.Web.UI.IParserAccessor @__parser = ((System.Web.UI.IParserAccessor)(@__ctrl));
#line 1 "C:\dev\Web.UI\Content\Shared\ToolbarControl.ascx"
@__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n<div class=\"toolbar\">\r\n "));
#line default
#line hidden
global::System.Web.UI.HtmlControls.HtmlGenericControl @__ctrl1;
#line 1 "C:\dev\Web.UI\Content\Shared\ToolbarControl.ascx"
@__ctrl1 = this.@__BuildControldivDelete();
#line default
#line hidden
#line 1 "C:\dev\Web.UI\Content\Shared\ToolbarControl.ascx"
@__parser.AddParsedSubObject(@__ctrl1);
#line default
#line hidden
#line 1 "C:\dev\Web.UI\Content\Shared\ToolbarControl.ascx"
@__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n <div class=\"toolbarSpacer\"></div>\r\n <div class=\"toolbarButton\">"));
et cetera
What I found interesting is that properties such as one might set in the Page directive are not included in these auto-generated files. This leads me to believe that the directive in its completeness is processed on each request and is not compiled along with the page.
EDIT #2: Per BurningIce's comment below, I dug into this further. I believe directive attributes can be described as follows.
Each of the attributes on a directive serves one or more of the following purposes: A hint to the compiler (such as the codebehind path), a hint to load the page (such as what class the page inherits from), a hint to render the page (such as MasterPageFile), and/or a property to set on each instance of the page that is created (such as Title).
The page directive is a mix of properties that you can set directly on the Page-object itself and instructions to the asp.net compiler.
This page shows a list of all properties http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx.
Quote from the page: Defines page-specific (.aspx file) attributes used by the ASP.NET page parser and compiler.
"" These NEW pages will show a list of all properties and somewhat of an explanation of the properties/attributes:
The old link noted above, http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx , is no longer useful. The newest links are, by objectives, at http://msdn.microsoft.com/en-us/library/t8syafc7(v=vs.100).aspx and http://msdn.microsoft.com/en-us/library/vstudio/ydy4x04a(v=vs.100).aspx , for all seeking this info.
精彩评论