Why is @MasterType directive not implied when setting @Page masterPageFIle?
Asked Answered
J

1

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?

Jentoft answered 28/1, 2010 at 14:54 Comment(1)
+1 I've wondered that so many times myself!Siobhan
P
2

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

Pinchpenny answered 28/1, 2010 at 15:0 Comment(2)
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.Jentoft
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.Pinchpenny

© 2022 - 2024 — McMap. All rights reserved.