why we use @Master type?

2019-01-24 05:24发布

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" %>

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)

1条回答
Juvenile、少年°
2楼-- · 2019-01-24 06:00

From MSDN you are defining the type of the MasterPage not just the Base class type of Master, it also allows you to access the MasterTypes properties directly.

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;
查看更多
登录 后发表回答