Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
124 views
Welcome To Ask or Share your Answers For Others

1 Answer

From Microsoft Docs you are defining the type of the Master property, which allows you to access the properties of your MasterPage derived class.

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.

As an example:

this.Master.SomePublicPropertyOfMaster = Value;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...