ASP.NET Master Page & Dynamic Page Title

Discussion in 'ASP .Net' started by Chris Walls, Jul 20, 2007.

  1. Chris Walls

    Chris Walls Guest

    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
     
    Chris Walls, Jul 20, 2007
    #1
    1. Advertising

  2. "Chris Walls" <> wrote in message
    news:...

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


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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jul 20, 2007
    #2
    1. Advertising

  3. Chris Walls

    David Wier Guest

    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
     
    David Wier, Jul 20, 2007
    #3
  4. "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
     
    Mark Rae [MVP], Jul 20, 2007
    #4
  5. 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
    >
    >
     
    Cowboy \(Gregory A. Beamer\), Jul 20, 2007
    #5
  6. Chris Walls

    Chris Walls Guest

    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
     
    Chris Walls, Jul 24, 2007
    #6
  7. "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
     
    Mark Rae [MVP], Jul 24, 2007
    #7
  8. 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.
     
    Walter Wang [MSFT], Jul 25, 2007
    #8
  9. Chris Walls

    Chris Walls Guest

    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
     
    Chris Walls, Jul 25, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Silver
    Replies:
    1
    Views:
    742
    Alan Silver
    Nov 6, 2005
  2. Doug McCann
    Replies:
    1
    Views:
    1,079
    William Brogden
    Aug 5, 2004
  3. Laith Zraikat
    Replies:
    3
    Views:
    1,237
    Walter Wang [MSFT]
    Jul 6, 2006
  4. Replies:
    0
    Views:
    551
  5. Replies:
    1
    Views:
    569
    David
    Apr 24, 2007
Loading...

Share This Page