473,573 Members | 4,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3846
"Sunfire" <a_*****@sbcglo bal.netwrote in message
news:en******** ******@TK2MSFTN GP05.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.Mas ter.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().Repl ace("ASP."").Re place("_aspx"," .aspx");

or using request:

var name = Path.GetFileNam e(Request.FileP ath);

-- 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.Mas ter.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_*****@sbcglo bal.netwrote in message
news:uM******** ******@TK2MSFTN GP06.phx.gbl...
((Menu)this.Mas ter.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.GetFileNam e(Request.FileP ath);

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:uD******** ******@TK2MSFTN GP04.phx.gbl...
"Sunfire" <a_*****@sbcglo bal.netwrote in message
news:uM******** ******@TK2MSFTN GP06.phx.gbl...
>((Menu)this.Ma ster.FindContro l("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**@mar kNOSPAMrae.net]
Posted At: Monday, November 05, 2007 11:27 AM
Posted To: microsoft.publi c.dotnet.framew ork.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_*****@sbcglo bal.netwrote in message
news:en******** ******@TK2MSFTN GP05.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.Mas ter.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
1497
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
6958
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 header. I tried to put the link tag in the Master page, but the classes are not recognized in the Content Page. How do I use a StyleSheet with the...
7
6528
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 (stylesheet.css) file. On my content page i have a textbox inside the contentplaceholder.
1
2235
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, EventArgs e) {
8
6677
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 and also my first true attempt at using master pages. I tried setting up a style sheet with a simple setting to float an image to the right and it...
6
1477
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 I've been working to replace using ASP.NET master pages. Right now I'm trying to find a solution for some of our older and externally linked...
10
2114
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 Master pages as their master...) the entire page is refreshed - also the menu which belongs to the master, how can I fix it - so only the inside...
5
2706
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 file is added by the webcontrol. This prevents me having to remember to add the CSS file to the page if I use a certain webcontrol. I have a...
3
5896
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 CTMNet.master and I have tested it with no problems. I am now trying to use VS2008 to build my first application which would reference the master page. I...
0
7789
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7800
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8086
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5605
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1325
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1048
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.