Master Pages and User Controls in .NET 2.0
One of the great mysteries of .NET 2.0 is how to reference the class of a master page or user control from code-beside. This is where the MasterType and Reference directives come into play.
Master Page (from content page)
<% @ MasterType TypeName="ClassName" %>
<% @ MasterType VirtualPath="~/VirtualPath/Master.master" %>
User Control (from web form)
<% @ Reference Control VirtualPath="~/VirtualPath/UserControl.ascx" %>
After adding the MasterType or Reference directive, you should then be able to reference the master pages or user controls class from code-beside.




