Accessing a property on the MasterPage in ASP.NET 2.0
To access a property on the masterpage in ASP.NET 2.0 you have to cast it like this:
For a Web Application project
CType(MyBase.Master, WebApplication1.Site1)
Or for a website project
CType(MyBase.Master, MasterPage)
Or you can specify the MasterType in the aspx like this:
For a Web Application project
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master"
CodeBehind="Default.aspx.vb"
CodeBehind="Default.aspx.vb"
Inherits="WebApplication1._Default" %>
<%@ MasterType TypeName="WebApplication1.Site1" %>
Or for a website project
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="Default" title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
Which will then create a shadow property on Master that does the casting for you so in the code behind you can just use:
Me.Master
Comments
Post a Comment