如果我们有母版页和内容页。那么内容页@Page 指令看起来像
<%@ Page Language="C#" MasterPageFile="~/Site1.Master" .... />
所以,为了访问内容页中的母版页控件,我们必须使用
<%@ MasterType VirtualPath="~/Site1.Master" %>
所以,我的问题是,当我们已经在 @page 指令中定义此内容页位于母版页(此处 -- Site1.Master)中时,为什么我们使用 @MasterType 指令
最佳答案
来自 Microsoft Docs您正在定义 Master
属性的类型,它允许您访问 MasterPage 派生类的属性。
Provides a way to create a strongly typed reference to the ASP.NET master page when the master page is accessed from the Master property.
举个例子:
this.Master.SomePublicPropertyOfMaster = Value;
关于c# - 为什么我们使用@Master类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8946742/