Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET Master Page & Dynamic Page Title

Reply
Thread Tools

ASP.NET Master Page & Dynamic Page Title

 
 
Chris Walls
Guest
Posts: n/a
 
      07-20-2007
We have a web application that is using a master page. This application is
being localized for multiple languages so for that, and other reasons, we
would like set the page title in my code behind. We've tried using the
following syntax. It doesn't raise an exception, but the title is not being
updated to the desired text.

this.Master.Page.Title = "My Page Title";

How can we programtically set the page title from a content page? Any help
would be appreciated.

- Chris


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      07-20-2007
"Chris Walls" <> wrote in message
news:...

> this.Master.Page.Title = "My Page Title";


Header.Title = ".........";


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
 
David Wier
Guest
Posts: n/a
 
      07-20-2007
I'm curious - normally the master page doesn't set the title, since each
content page has it's own, that you can set either in the property window,
or by code-behind:
me.title="whatever"
Are you setting the page title for every content page, in the master page?

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com



"Mark Rae [MVP]" <> wrote in message
news:...
> "Chris Walls" <> wrote in message
> news:...
>
>> this.Master.Page.Title = "My Page Title";

>
> Header.Title = ".........";
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      07-20-2007
"David Wier" <> wrote in message
news:%...

> I'm curious - normally the master page doesn't set the title, since each
> content page has its own, that you can set either in the property window,
> or by code-behind:
> me.title="whatever"


That's right.

> Are you setting the page title for every content page, in the master page?


I'm not - the OP may be, though...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      07-20-2007
The Master Page title is only used if there is nothing else to grab onto.
While it appears as a container, it is actually a control in the ASPX page.
You want to set the title of the Header, as Mark has stated.

For globalization, you can also use the title="" in the @Page directive and
set it to a resource string. If you are using custom resource providers, you
may have to do a bit of magic here in the Page_Init routine, but if you are
using standard resource files, it is the same as any other resource tag
pulling from the file rather than meta.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
"Chris Walls" <> wrote in message
news:...
> We have a web application that is using a master page. This application
> is being localized for multiple languages so for that, and other reasons,
> we would like set the page title in my code behind. We've tried using the
> following syntax. It doesn't raise an exception, but the title is not
> being updated to the desired text.
>
> this.Master.Page.Title = "My Page Title";
>
> How can we programtically set the page title from a content page? Any
> help would be appreciated.
>
> - Chris
>
>



 
Reply With Quote
 
Chris Walls
Guest
Posts: n/a
 
      07-24-2007
Didn't work. No exception thrown but the HTML title tag does not contain
the value I'm setting Header.Title to.

To answer other questions, I'm not setting the title from the master page,
I'm trying to set it programatically from the content page, though
unsuccessfully.


"Mark Rae [MVP]" <> wrote in message
news:...
> "Chris Walls" <> wrote in message
> news:...
>
>> this.Master.Page.Title = "My Page Title";

>
> Header.Title = ".........";
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      07-24-2007
"Chris Walls" <> wrote in message
news:%23FDa$...

> Didn't work. No exception thrown but the HTML title tag does not contain
> the value I'm setting Header.Title to.


Where are you using the Header.Title = "...."; code? Can you put a
breakpoint on that line and inspect the value of Header.Title before and
after it runs...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      07-25-2007
Hi Chris,

Please try following test pages:

MasterPage.master:


<%@ Master Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Master Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>


Default2.aspx:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Content
Page" %>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
this.Header.Title = "Test";
}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>




The Default2.aspx should correctly show "Test" as the web page title.



Regards,
Walter Wang (, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Chris Walls
Guest
Posts: n/a
 
      07-25-2007
Got it now. We had a default title set in the master page's HTML. Once it
was removed, the code worked. It was thought this would be overwritten by
the content page's page_load method.

Thanks for the help.

"Mark Rae [MVP]" <> wrote in message
news:%...
> "Chris Walls" <> wrote in message
> news:%23FDa$...
>
>> Didn't work. No exception thrown but the HTML title tag does not contain
>> the value I'm setting Header.Title to.

>
> Where are you using the Header.Title = "...."; code? Can you put a
> breakpoint on that line and inspect the value of Header.Title before and
> after it runs...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Friendly Urls with page title in (eg. page-title.aspx) anthonykallay@googlemail.com ASP .Net 1 04-24-2007 08:25 AM
How 2 place page title into window title using sitemap in master page? bednar.tomas@gmail.com ASP .Net 0 11-30-2006 03:17 PM
Setting the Page Title using local resources for a content page in a master page Laith Zraikat ASP .Net 3 07-06-2006 01:23 AM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM
Fastest way to get a the string between <title> </title> Andreas Klemt ASP .Net 1 08-10-2003 01:58 AM



Advertisments