Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

ASP.NET Master Page & Dynamic Page Title

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Walls - 20 Jul 2007 14:25 GMT
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
Mark Rae [MVP] - 20 Jul 2007 14:31 GMT
>    this.Master.Page.Title = "My Page Title";

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

Signature

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

David Wier - 20 Jul 2007 14:56 GMT
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?

Signature

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

>>    this.Master.Page.Title = "My Page Title";
>
> Header.Title = ".........";
Mark Rae [MVP] - 20 Jul 2007 15:05 GMT
> 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...

Signature

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

Chris Walls - 24 Jul 2007 21:24 GMT
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.

>>    this.Master.Page.Title = "My Page Title";
>
> Header.Title = ".........";
Mark Rae [MVP] - 24 Jul 2007 21:36 GMT
> 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...?

Signature

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

Chris Walls - 25 Jul 2007 18:38 GMT
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.

>> 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...?
Walter Wang [MSFT] - 25 Jul 2007 06:35 GMT
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 (wawang@online.microsoft.com, 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.
Cowboy (Gregory A. Beamer) - 20 Jul 2007 17:28 GMT
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.

Signature

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!
************************************************

> 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,
[quoted text clipped - 8 lines]
>
> - Chris

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.