Add the following declaration to
content pages to allow easy access to master page public
properties and controls.
<%@ MasterType VirtualPath="~/MasterPageName.master"%>
This will allow you to reference a public property or control by
making a call like “me.master.PropertyName”. Extra
code to cast would be needed if you did not specify the
MasterType.
MasterType can also be set when
using nested master pages, but you will not be able to reference
the top master's controls without creating a public property
for each.
Setup nested master pages as shown below.
<%@ Master Language="VB" CodeFile="MasterPageInner.master.vb" Inherits="MasterPageInner" MasterPageFile="~/MasterPageOuter.master"%>
<%@ MasterType VirtualPath="~/MasterPageOuter.master"%>
<asp:Content ContentPlaceHolderID="ContentOuter" runat=server>
<asp:contentplaceholder id="ContentInner" runat="server">
</asp:contentplaceholder>
</asp:Content>
Content page:
<%@ Page Language="VB" MasterPageFile="~/MasterPageInner.master" AutoEventWireup="false" CodeFile="MasterTypeTest.aspx.vb" Inherits="MasterTypeTest" title="Untitled
Page" %>
<%@ MasterType VirtualPath="~/MasterPageInner.master" %>
<%@ Reference VirtualPath="~/MasterPageOuter.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentInner" Runat="Server">
<asp:Literal ID="LitTest" runat="server"></asp:Literal>
</asp:Content>