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

S

Sunfire

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?
 
M

Mark Rae [MVP]

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"))........
 
G

Guest

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)
 
S

Sunfire

((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?
 
M

Mark Rae [MVP]

((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...
 
S

Sunfire

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);
 
D

Dave Bush

Just wrote about this. Rather than redo the entire article, here's the
link:
http://blog.dmbcllc.com/2007/11/05/how-to-properly-access-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:[email protected]]
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?

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"))........
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top