473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 3835
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: needin4mation | last post by:
protected void Page_Load(object sender, EventArgs e) { TextBox mpTextBox = (TextBox)(Master.FindControl("txtFreeSearch")); Response.Write("mp" + mpTextBox.Text); //only works the second time ...
2
by: SR | last post by:
I have started a web site using ASP.NET 2.0. I would like to centralize all of my classes in a StyleSheet but I cannot figure out how to link the StyleSheet to a Content Page since there is no...
7
by: pushpadant | last post by:
Hi, I have one master page which has some table inside one of the <td> i have my contentplaceholder. on the <head> tag of the master page i have specified link to a global CSS...
1
by: Alan Samet | last post by:
I know what's causing this, but how do I work around it? ********************** file: test.master: ********************** <%@ Master %> <script runat=server> void Page_Load(object sender,...
8
by: JT | last post by:
Hi, I have done a fair amount of style editing inline in ASP. I'm now using VS 2005 with a standard web project (not Web Application Project). This is my first foray into CSS in a style sheet...
6
by: emorgoch | last post by:
Hi there. I'm currently working on a project involving rebuilding our local intranet site. The site was originally developed using frames, defining a header, sidebar, and content area, which...
10
by: =?Utf-8?B?RGFuaQ==?= | last post by:
Hi, Trying to create a master page that holds a menu, and the menu switches between pages in the site. 2 problem arrosed: a. When I navigate from page to page (all AJAX Web Forms, with the...
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...
3
by: =?Utf-8?B?U3RldmUgTGFGb3JnZQ==?= | last post by:
I have an intranet site and want to create a simple master page to be shared across all applications that are built for that site. I build my master page in c:\inetpub\wwwroot\Masters as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.