Set title in master page

R

Roshawn

Hi,

How do I set the title in a master page from a content page, assuming that I don't set the content page's title property in
the .aspx file but rather in the codebehind file? (The reason I ask is because the title in the content page is dynamic.)

Thanks,
Roshawn
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

How about this code?

Me.Master.Page.Title = "Whatever"
 
R

Roshawn

Hi Mark and thanks for the reply. I gave your suggestion a try but no results. The master page ignores it, although no
errors are thrown.
 
R

Roshawn

Hey, I've got it!!! :)

I declared a variable as an HtmlTitle and set its text property. When done I added this variable to the controls collection
of the content page's headers property. It looks like this:

Dim html As New HtmlTitle

html.Text = "Some Name Here"

Me.Headers.Controls.Add(html)

Cheers,
Roshawn
 
M

Mark Rae

Hey, I've got it!!! :)

I declared a variable as an HtmlTitle and set its text property. When
done I added this variable to the controls collection of the content
page's headers property. It looks like this:

Dim html As New HtmlTitle

html.Text = "Some Name Here"

Me.Headers.Controls.Add(html)

Good that you've got it working, but I've never seen that method before...

Header.Title = "..." has always worked for me...

Anyone know why it doesn't work for the OP...?
 
R

Roshawn

My bad!! :-( It actually does work. The title is derived from a querystring value. Stupid (that's me) forgot to get that
value.

Oh well, who says that you can be a genius everyday. :)

Cheers,
Roshawn
 
M

Mark Rae

My bad!! :-( It actually does work. The title is derived from a
querystring value. Stupid (that's me) forgot to get that value.

Fab! Thought I was going mad there...
 
C

clintonG

I would say the other suggested methods are not working because the content
page requires a cast to the Master to reference its members. That's why the
OP probably has no Intellisense in the content page for any members of the
Master as well.

Go to http://www.odetocode.com where Scott Allen has written up perhaps the
best articles providing insight into the use of MasterPages. Dino Espinoza
reviews these issues in the latest aspnet.Pro magazine where Steve Orr who
commented in this news topic also wrote up a second article about passing
values between pages. Good stuff...

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h
 
A

Alastair

This is the way I did it. I have a string variable in the code-behind
which contains a string that I want to use as the title.

Create a protected property in the code behind

private string _myPageHeader;
..
..
..
protected string MyPageHeader
{
get { return _myPageHeader; }
}

In the <title> </title> tags do the following:-

<title>
<% Response.Output.Write (MyPageHeader); %>
</title>

Works for me!
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top