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

编程入门 行业动态 更新时间:2024-10-27 12:28:32
本文介绍了为什么我们使用@Master类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我们有一个母版页和一个内容页.那么内容页@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类型?

本文发布于:2023-10-26 01:08:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   Master

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!