如果我们有一个母版页和一个内容页.那么内容页@Page指令看起来像
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" %>所以,我的问题是,为什么我们已经在@page指令中定义了该内容页面在母版页(此处为Site1.Master)中时使用@MasterType指令
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)
推荐答案来自 Microsoft文档,您正在定义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.
提供了一种从Master属性访问母版页时创建对ASP.NET母版页的强类型引用的方法.
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;更多推荐
为什么我们使用@Master类型?
发布评论