views:

38

answers:

2

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 the @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?

+2  A: 

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).

Tim
There are properties on the page directive that doesn't correspond to a property on the Page-object, like Codebehind or codefile, so it makes sence that it can't be compiled.Reading this page http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx it gives a clear impression that many of the directive attributes are more like instructions to the compiler.
BurningIce
Just to clear up, that none of the attributes in the directive are used at runtime, its all at compile time. This is clear to see if you try to use the aspnet_compiler.exe to precompile your website. You'll find that your .aspx-files becomes obsolete so there is no runtime information, since there are no .aspx-files left to read.
BurningIce
+1  A: 

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.

BurningIce
+1 for adding detail to my post. I think each of the attributes sets a property on the page, serves as a hint to the compiler, or serves as a hint to the runtime. For example, MasterPageFile dictates what master is merged with the ASPX at runtime and this property can also be specified in OnInit (or OnPreInit, I forget which).
Tim
the properties are all used at compile time, so either they are compiler-specific or sets some properties on the Page-object. If you try to use the aspnet_compiler.exe to precompile your website, you'll find that your .aspx-files becomes obsolete so there is no runtime information left back, since there are no .aspx-files left to read.
BurningIce