470,591 Members | 1,585 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Checking to see what page is loaded from inside a master page file?

Is there a way you can test what page is loaded from inside a master page?
What I need to do is test to see what page is loaded inside the master page
and then gray out the root item linked to that page in the Menu control.
I.e. I have a root item called home. When a person is on the home page I
want it to be disabled. Any way to do this?

Nov 5 '07 #1
6 3693
"Sunfire" <a_*****@sbcglobal.netwrote in message
news:en**************@TK2MSFTNGP05.phx.gbl...
Is there a way you can test what page is loaded from inside a master page?
What I need to do is test to see what page is loaded inside the master
page and then gray out the root item linked to that page in the Menu
control. I.e. I have a root item called home. When a person is on the home
page I want it to be disabled. Any way to do this?
You're confusing MasterPages with framesets...

A MasterPage doesn't load the content page - it's the other way round...

When a content page loads, it interrogates its MasterPage property and then
combines itself with it to create a single page. In fact, a MasterPage is
just a UserControl...

It's simple enough to get a content page to modify its MasterPage, however -
you can create a property on the MasterPage for the content page to set, or
you can do something like:

((Menu)this.Master.FindControl("MyMenu"))........
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 5 '07 #2
as stated the master page is a control on the actual page. so to get the name
its just:

var name =
Page.GetType().ToString().Replace("ASP."").Replace ("_aspx",".aspx");

or using request:

var name = Path.GetFileName(Request.FilePath);

-- bruce (sqlwork.com)
"Sunfire" wrote:
Is there a way you can test what page is loaded from inside a master page?
What I need to do is test to see what page is loaded inside the master page
and then gray out the root item linked to that page in the Menu control.
I.e. I have a root item called home. When a person is on the home page I
want it to be disabled. Any way to do this?

Nov 5 '07 #3
((Menu)this.Master.FindControl("MyMenu"))........
Just one more question. Does the above line of code return a value or does
it act like a control?

Nov 5 '07 #4
"Sunfire" <a_*****@sbcglobal.netwrote in message
news:uM**************@TK2MSFTNGP06.phx.gbl...
((Menu)this.Master.FindControl("MyMenu"))........
Just one more question. Does the above line of code return a value or does
it act like a control?
Strictly speaking, it sets a reference to a control on the MasterPage and
casts it to the correct type - thereafter, you can modify its properties
etc...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 5 '07 #5
Hi... I found my answer... the code below helped me out. Somebody on this
thread had given it to me and it works. Don't remember their name though...

var name = Path.GetFileName(Request.FilePath);

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uD**************@TK2MSFTNGP04.phx.gbl...
"Sunfire" <a_*****@sbcglobal.netwrote in message
news:uM**************@TK2MSFTNGP06.phx.gbl...
>((Menu)this.Master.FindControl("MyMenu"))...... ..
Just one more question. Does the above line of code return a value or
does it act like a control?

Strictly speaking, it sets a reference to a control on the MasterPage and
casts it to the correct type - thereafter, you can modify its properties
etc...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 5 '07 #6
Just wrote about this. Rather than redo the entire article, here's the
link:
http://blog.dmbcllc.com/2007/11/05/h...controls-in-th
e-master-page/

It talks about accessing a TD in the master page from the aspx page.
You could do something similar to set your menu. We do it all the time.
Even have one app where the background color of the screen changes based
on the page you are on.

-----Original Message-----
From: Mark Rae [MVP] [mailto:ma**@markNOSPAMrae.net]
Posted At: Monday, November 05, 2007 11:27 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Checking to see what page is loaded from inside a master
page file?
Subject: Re: Checking to see what page is loaded from inside a master
page file?

"Sunfire" <a_*****@sbcglobal.netwrote in message
news:en**************@TK2MSFTNGP05.phx.gbl...
Is there a way you can test what page is loaded from inside a master
page?
What I need to do is test to see what page is loaded inside the master
page and then gray out the root item linked to that page in the Menu
control. I.e. I have a root item called home. When a person is on the
home
page I want it to be disabled. Any way to do this?
You're confusing MasterPages with framesets...

A MasterPage doesn't load the content page - it's the other way round...

When a content page loads, it interrogates its MasterPage property and
then
combines itself with it to create a single page. In fact, a MasterPage
is
just a UserControl...

It's simple enough to get a content page to modify its MasterPage,
however -
you can create a property on the MasterPage for the content page to set,
or
you can do something like:

((Menu)this.Master.FindControl("MyMenu"))........
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 5 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by needin4mation | last post: by
1 post views Thread by Alan Samet | last post: by
6 posts views Thread by emorgoch | last post: by
10 posts views Thread by =?Utf-8?B?RGFuaQ==?= | last post: by
5 posts views Thread by =?Utf-8?B?bXVzb3NkZXY=?= | last post: by
3 posts views Thread by =?Utf-8?B?U3RldmUgTGFGb3JnZQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.