c# - 为什么我们使用@Master类型?

标签 c# asp.net master-pages content-pages

如果我们有母版页和内容页。那么内容页@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/

相关文章:

c# - Orchard - 移动页面标题

c# - 如何在 C# 中将文件存储在共享网络驱动器上

javascript - Response.Write JavaScript 警报不显示任何内容

.net - 使用 Masterpage 在 ASP.Net 页面上进行 javascript 验证的最佳方法是什么?

c# - Azure:将凭据传递给需要错误类型的 ComputeManagementClient 构造函数

c# - 注册 .NET Core 身份名称字段错误 - "User name ' '无效,只能包含字母或数字。”

c# - 如何处理/取消同一用户 asp.net 的并发请求

c# - 可折叠的主细节 GridView 结构

asp.net - 哪个事件首先调用?母版页 Page_Load 或内容页 Page_Load

c# - ASP.NET 动态添加 UserControl 到 PlaceHolder,不触发 Click 事件,只触发 Page_Load