为什么我们使用@Master类型? [英] why we use @Master type?

查看:270
本文介绍了为什么我们使用@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)

推荐答案

来自

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类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆