472,984 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,984 software developers and data experts.

Accessing properties from nested master pages

I have this cool nested master page scenario working great. However what is
the correct way to be able to access a strongly typed property at the top
level master from a content page that has a nested master page between the
content page and the top level master?

For example, assume the very top level master is called CompanyWide.master.
And the nested master page is called DepartmentA.master, which inherits from
CompanyWide master. Last I have a content page test.aspx that is created
with DepartmentA as its master page.

OK so now from the test.aspx page's code behind I want to set a public
property defined in CompanyWide master. However even though the property is
Public in CompanyWide master, I am not sure how to access it since there is
another master page in between it (DepartmentA.master).

What is the right way to do this?

Do I have to recreate these public properties in DepartmentA to act as a
stub, so I then call them from test.aspx and it takes them in the setter and
then sets them in the master? That seems quite messy - wouldn't think that
would be the way.

So I thought that maybe DepartmentA master would inherit CompanyWide
master's public properties since DepartmentA is a nested master of it. But
when I try:
(DepartmentA).this.Master I do not see the properties in CompanyWide's so
it doesn't look like they were inherited. And I cannot do this:
(CompanyWide).this.Master because test.aspx does not know what type
"CompanyWide" is.

Can someone please point me in the right direction here?

Thanks,

Steve
Nov 19 '05 #1
4 2424
You should be able to use ((DepartmentA)this.Master).Property or
(this.Master as DepartmentA).Property

"Steve Franks" <pl****@postreplyhere.com> wrote in message
news:Hs********************@comcast.com...
I have this cool nested master page scenario working great. However what
is the correct way to be able to access a strongly typed property at the
top level master from a content page that has a nested master page between
the content page and the top level master?

For example, assume the very top level master is called
CompanyWide.master. And the nested master page is called
DepartmentA.master, which inherits from CompanyWide master. Last I have a
content page test.aspx that is created with DepartmentA as its master
page.

OK so now from the test.aspx page's code behind I want to set a public
property defined in CompanyWide master. However even though the property
is Public in CompanyWide master, I am not sure how to access it since
there is another master page in between it (DepartmentA.master).

What is the right way to do this?

Do I have to recreate these public properties in DepartmentA to act as a
stub, so I then call them from test.aspx and it takes them in the setter
and then sets them in the master? That seems quite messy - wouldn't think
that would be the way.

So I thought that maybe DepartmentA master would inherit CompanyWide
master's public properties since DepartmentA is a nested master of it.
But when I try:
(DepartmentA).this.Master I do not see the properties in CompanyWide's so
it doesn't look like they were inherited. And I cannot do this:
(CompanyWide).this.Master because test.aspx does not know what type
"CompanyWide" is.

Can someone please point me in the right direction here?

Thanks,

Steve

Nov 19 '05 #2
I thought so too and had tried that before posting. It does not work
though.

Steve

"Graham" <en*******@newsgroups.nospam> wrote in message
news:uC****************@TK2MSFTNGP12.phx.gbl...
You should be able to use ((DepartmentA)this.Master).Property or
(this.Master as DepartmentA).Property

Nov 19 '05 #3
OK, I figured it out. Here it is:
((CompanyWide)this.Master.Page.Master).HtmlTitle = "now it is working";

Be sure you do NOT have a <%@ MasterType VirtualPath="~/whatever.master" %>
declared or you will get an InvalidCastException thrown at runtime.

I hope this helps someone else one day.

Steve
Nov 19 '05 #4
You can do Master.Master.PropName as long as everyone in the chain has applied
a <%@ MasterType %>

http://beta.asp.net/QUICKSTART/aspne...ault.aspx#code

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have this cool nested master page scenario working great. However
what is the correct way to be able to access a strongly typed property
at the top level master from a content page that has a nested master
page between the content page and the top level master?

For example, assume the very top level master is called
CompanyWide.master. And the nested master page is called
DepartmentA.master, which inherits from CompanyWide master. Last I
have a content page test.aspx that is created with DepartmentA as its
master page.

OK so now from the test.aspx page's code behind I want to set a public
property defined in CompanyWide master. However even though the
property is Public in CompanyWide master, I am not sure how to access
it since there is another master page in between it
(DepartmentA.master).

What is the right way to do this?

Do I have to recreate these public properties in DepartmentA to act as
a stub, so I then call them from test.aspx and it takes them in the
setter and then sets them in the master? That seems quite messy -
wouldn't think that would be the way.

So I thought that maybe DepartmentA master would inherit CompanyWide
master's public properties since DepartmentA is a nested master of it.
But
when I try:
(DepartmentA).this.Master I do not see the properties in
CompanyWide's so
it doesn't look like they were inherited. And I cannot do this:
(CompanyWide).this.Master because test.aspx does not know what type
"CompanyWide" is.
Can someone please point me in the right direction here?

Thanks,

Steve

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Ferris | last post by:
Hello, I am having an issue with page breaking that I hope someone will be able to help me with. Still a relative "newbie", and I thought this might be a good place to find some help. I have a...
1
by: Diane Yocom | last post by:
I have two nested master pages, each with public properties. From my content page, I am able to access properties from both pages using either Master.PropertyName (for the child master page) or...
3
by: Rolf Welskes | last post by:
Hello, for a large web site project we would like to use nested Master Pages. Unfortunely VS2005 is not able to show pages in design mode when nested Master pages are used. This has the...
9
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method...
3
by: vespaboy | last post by:
i need to access a <div runat="server"which sits in a master page which is itself nested in a master page. i've tried this code but it doesn't work: Page: Dim divStep1 As HtmlGenericControl =...
4
by: evantay | last post by:
I'm using ASP.NET 2.0 with VS.NET 2005. I'm trying to access properties from my master pages within a page that inherits from that master page (a child page). However the values are always null....
0
by: evantay | last post by:
I'm using ASP.NET 2.0 with VS.NET 2005. I'm trying to access properties from my master pages within a page that inherits from that master page (a child page). However the values are always null....
4
by: daveh551 | last post by:
I've seen reference to Nested Master Pages in some of the documentation, but I haven't been successful in creating one in VS 2005 (Framework 2.0). I just did a search on it, and "How To:...
5
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm trying to make my code as streamlined as possible, and add CSS file references dynamically when they are required, for example, if a page contains a webcontrol, then the related CSS...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.