473,378 Members | 1,346 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,378 software developers and data experts.

Getting current page in Master Page

I have a Master Page that I use for several web pages. In the code-behind
of the Master Page I have a Page_Load event that sets some information
inside the controls of the Master Page (see example below).

I would like to alter some of the Text properties of controls in the
MasterPage based on the page name, e.g. Default.aspx, HomePage.aspx, etc.
How do I determine the name of the web page that is opening? Thanks.

David

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
LblTitle.Text = "New Web Page"
LBtnPhotos.Text = "Initial Photos"
End Sub
Nov 5 '08 #1
2 16927
"David C" <dl*****@lifetimeinc.comwrote in message
news:e$**************@TK2MSFTNGP05.phx.gbl...
How do I determine the name of the web page that is opening?
The most important thing to remember about a MasterPage is that it is
nothing more than a UserControl.

The biggest mistake people make about MasterPages is to imagine that a
MasterPage "owns" a content page when, in fact, it is the other way round.

Therefore, if a MasterPage needs to know on which page it is being used, it
just needs to inspect its Parent property, e.g.

protected void Page_Init(object sender, EventArgs e)
{
switch (this.Parent.ToString())
{
case "........" :
{
// do something
break;
}
case "........" :
{
// do something
break;
}
}
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 5 '08 #2
Study the Path class particularly Path.GetFileName(...)
"David C" <dl*****@lifetimeinc.comwrote in message
news:e$**************@TK2MSFTNGP05.phx.gbl...
>I have a Master Page that I use for several web pages. In the code-behind
of the Master Page I have a Page_Load event that sets some information
inside the controls of the Master Page (see example below).

I would like to alter some of the Text properties of controls in the
MasterPage based on the page name, e.g. Default.aspx, HomePage.aspx, etc.
How do I determine the name of the web page that is opening? Thanks.

David

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
LblTitle.Text = "New Web Page"
LBtnPhotos.Text = "Initial Photos"
End Sub
Nov 5 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sascha Folville | last post by:
Hi, I'm trying to transform a XML document to PDF using apache (xerces). I want different formatting for first and last page. My code looks like this: <fo:layout-master-set>...
0
by: Nathan | last post by:
Hi, I seem to having a peculiar problem with the display of odd and even pages in XSL-FO. Here is a small background of the problem. My xsl stylesheet mentions my fo:layout-master-set as ...
0
by: Abraham Andres Luna | last post by:
i have a master page: <%@ Master Language="C#" %> <html> <head> <title>CRM - RDK Truck Sales & Service</title> </head> <body> <form runat="server"> <asp:contentplaceholder...
2
by: gencode | last post by:
I have a logout link in a master page...when the link is pressed I want to capture that event in the child page, not the master page, becase there is some processing I want to do in the child...
5
by: christianlott1 | last post by:
I admit my form is pretty complex and may need a total overhaul - I have two subforms synchronized on a form through an unbound text box. When I enter a new record in the second subform it used...
8
by: Amit | last post by:
I have a master page and a content page but the stylesheet isnt getting applied like how it looks in visual studio design view. The master page is defined like this: <%@ Master Language="VB"...
2
by: Chip Pearson | last post by:
This is probably an extremely simple question. How do I get a page's own URL? In the footer section of my Master page, I want a Label control that will be updated with the page's own URL. ...
3
by: adamjee | last post by:
I am passing an Object using Session from one form to other. pm.a = a; pm.b = b; e.g. Session = pm; OK, it passes and i receive it another form. at second form, I received it on Page Load...
3
by: skanemupp | last post by:
so i load a gif onto a canvas and when i click the canvs i want to get the color of the pixel that is clicked. so i need to ge the object im clicking. i was told in another thread to use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.