using TypeName with MasterType directive

In the past I have only used Virtual Path attribute with MasterType directive. Using the MasterType attribute gives the page a strongly typed master page instead of casting the master page to correct type and accessing the property.  But what happens if you specifying the master page dynamically based on condition. In that case virtual path attribute would not work because you do not know what master page you are going to be inheriting from. The solution is to create a base master page and put your common master page properties in the base class. Now in order to get a strongly typed references to master page properties in your pages, use the MasterType directive with TypeName attribute which you can set to your custom master page class. here is an example.

image

image

No Comments