MasterType directive

In the past, if I had to access specific property of a master page from my content page, I usually would cast my master page to right type and get access to property but this could lead to runtime errors. Today I discovered that you can apply master type directive on your content page to make your master page reference strongly typed. Once you apply the MasterType directive, you no longer have to cast the Master Page to correct type because it is casted to the right type already. Here is snippet that you can put in your content page.

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

No Comments