471,354 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 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 2345
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Joseph Ferris | last post: by
1 post views Thread by Diane Yocom | last post: by
9 posts views Thread by J055 | last post: by
3 posts views Thread by vespaboy | last post: by
5 posts views Thread by =?Utf-8?B?bXVzb3NkZXY=?= | last post: by

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.