views:

154

answers:

1

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?

+1  A: 

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

Dirk
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.
Sam
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