8

The docs for @MasterType have this example.

<%@ Page  masterPageFile="~/MasterPage.master"%>
<%@ MasterType  virtualPath="~/MasterPage.master"%> 

Why is @MasterType even needed? Couldn't the compiler automatically take the same actions based solely on @Page masterPageFile? When would you not want to use both?

MPritchard
  • 7,031
  • 7
  • 28
  • 40
Samuel Neff
  • 73,278
  • 17
  • 138
  • 182

1 Answers1

2

You can set different master pages at each pages PreInit. So the master page is in general not well defined.

Dirk Brockhaus
  • 4,922
  • 3
  • 38
  • 47
  • 1
    In this case I expect you wouldn't use either directive 'cause it's defined at runtime and you also wouldn't expect to get a typed `Master` property. The question is really directed towards situations where you do use the directives and the master page is known at compile time. – Samuel Neff Jan 28 '10 at 15:10
  • But there is only one situation. Page and master page are loosely coupled. You can change the master page at runtime. The MasterPage directive is just a smart cast for simple situations and you have to take the full responsibility for it. – Dirk Brockhaus Jan 28 '10 at 15:30