为什么我们使用@Master类型?
如果我们有一个母版页和一个内容页。那么内容页@Page指令看起来像这样
<%@ Page Language="C#" MasterPageFile="~/Site1.Master" .... />
,为了访问内容页中的母版页控件,我们应该使用
<%@ MasterType VirtualPath="~/Site1.Master" %>
so,我的问题是这为什么我们使用@MasterType指令当我们已经在 @page 指令中定义该内容页面位于母版页中时(此处为 Site1.Master)
if we have a master page and a content page.so the content page @Page directive look like as
<%@ Page Language="C#" MasterPageFile="~/Site1.Master" .... />
so , in order to access master page controls in content page we should have to use
<%@ MasterType VirtualPath="~/Site1.Master" %>
so , my question is this why we use @MasterType directive when we already define in the @page directive that this content page is in the master page (here -- Site1.Master)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 Microsoft Docs,您是定义
Master
属性的类型,它允许您访问 MasterPage 派生类的属性。举个例子:
From Microsoft Docs you are defining the type of the
Master
property, which allows you to access the properties of your MasterPage derived class.As an example:
使用
MyMasterPage
类型指定 @MasterType 指令会在代码隐藏类中产生以下属性定义:此属性定义由 BuildMiscClassMembers 方法
TemplateControlCodeDomTreeGenerator
类的。Specifying the @ MasterType directive with a type of
MyMasterPage
results in the following property definition in the code behind class:This property definition is created by the BuildMiscClassMembers method of the
TemplateControlCodeDomTreeGenerator
class.