Ron,
On your page which is utilizing the master page you can set the master
page's type. After doing so you can access all shared/public properties,
components, etc. on your master page referencing them using
Master.[control/property]
So, here's what you do:
Add this to your .aspx page (just below the page declaration):
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="Auction.aspx.vb" Inherits="Auction"
title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>
And here's an excerpt from an article about it:
Accessing a Master Page from Code
In addition to overriding content, it is possible for a Content Page to
programmatically access its Master Page. A Content Page creates a
strongly-typed reference to the Master Page using the <%@ MasterType %>
directive, specifying the virtual path to the master page:
<%@ MasterType VirtualPath="Site.master" %>
The Content Page can then reference the Master Page using the Master
property of the Page class:
C#
Master.FooterText = "This is a custom footer";
AdRotator ad = (AdRotator)Master.FindControl("MyAdRotator");
VB
Master.FooterText = "This is a custom footer"
Dim ad As AdRotator = Master.FindControl("MyAdRotator")
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Ron" <ro******@web2office.biz> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi all,
I've come across a problem when casting user controls in ASP.NET 2.0,
hopefully someone can help. I have a master page with a user control on
it (myMenu) that I wish to programmatically access from a content page.
Below is how I am trying to do this (this would work in ASP.NET 1.1).
DynamicMenu myMenu =
(DynamicMenu)((MasterPage)this.Master).FindControl ("myMenu");
myMenu.initialise(enterpriseId);
However it doesn't work in 2.0 because I can't reference the user
control type DynamicMenu in code. I've tried adding the control to a
namespace, through which I could reference it, but apparently you can't
do this now.
Does anyone know how I could get this to work, or another way of doing
the same thing?
Thanks and Regards,
Ross