2

I have many master pages inside an asp.net web forms project.

For example, Sub.master is using Main.master as master page and the sub master has following directive:

<%@ MasterType VirtualPath="~/Main.master" %>

An experienced developer tells me to use it even I'm not accessing the Page.Master inside the sub master/page because it makes the page Strongly Typed. What are the pros and cons using this directive if any? Because I cannot decide if I should add it on every web form page too.

HasanG
  • 12,734
  • 29
  • 100
  • 154

2 Answers2

1

It 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.

See

VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • So you're saying no advantage when not used? – HasanG Jul 10 '17 at 13:19
  • 1
    Strongly types is always better. It reduces the chance for conversion errors. However if you do not need to access properties on the Master page then you don't really need it either. – VDWWD Jul 10 '17 at 13:29
0

At first glance it looks good but I never liked direct access to an object,control or method belonging to the master page.

I think there must be a standard of communication like event bubbling (master to child or child to master).

<%@ MasterType TypeName="BaseMaster" %> seems to be good in establishing this standard.

levent
  • 3,464
  • 1
  • 12
  • 22