简体   繁体   English

什么是.NET中的页面指令

[英]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... MS考试网站的开发Web表单页面”下 ,它说明了考试内容......

This objective may include but is not limited to: page directives such as ViewState, request validation, event validation, MasterPageFile; 此目标可能包括但不限于:页面指令,如ViewState,请求验证,事件验证,MasterPageFile; ClientIDMode; 的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. 我的印象是页面指令引用了@Page关键字,而@Page部分中定义的关联值是属性/属性。 But the wording of the exam content almost implies that the attributes/properties of the @Page keyword are directives. 但是考试内容的措辞几乎意味着@Page关键字的属性/属性是指令。

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 (eg in the codebehind). 实际上,您可以在对象模型中设置大多数这些AS属性(例如,在代码隐藏中)。

 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 . 除了Page之外,它们还有几个重要的指令,例如ImportControl 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. 编辑:我很好奇这些属性在从Page指令设置时结束,所以我看了一下ASP.Net缓存。 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\\ c:\\ windows \\ Microsoft.Net \\ Framework [版本] \\临时ASP.Net文件\\

        [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. 我发现有趣的是,在Page指令中设置的属性不包含在这些自动生成的文件中。 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. 编辑#2:Per BurningIce的评论如下,我进一步深入研究。 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). 指令中的每个属性都有以下一个或多个用途:对编译器的提示(例如代码隐藏路径),加载页面的提示(例如页面继承的类),提示提示页面(例如MasterPageFile)和/或要在创建的页面的每个实例上设置的属性(例如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. page指令是一组混合属性,您可以直接在Page-object本身和asp.net编译器的指令上设置这些属性。

This page shows a list of all properties http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx . 此页面显示所有属性的列表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. 从页面引用: 定义ASP.NET页面解析器和编译器使用的页面特定(.aspx文件)属性。

"" 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. 上面提到的旧链接http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx不再有用。 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. 根据目标,最新的链接是http://msdn.microsoft.com/en-us/library/t8syafc7(v=vs.100).aspxhttp://msdn.microsoft.com/en-us/ library / vstudio / ydy4x04a(v = vs.100).aspx ,适合所有寻求此信息的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM