Set title in master page

Discussion in 'ASP .Net' started by Roshawn, Jan 9, 2007.

  1. Roshawn

    Roshawn Guest

    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
     
    Roshawn, Jan 9, 2007
    #1
    1. Advertising

  2. Roshawn

    Mark Rae Guest

    "Roshawn" <> wrote in message
    news:...

    > How do I set the title in a master page from a content page


    Header.Title = "......";
     
    Mark Rae, Jan 9, 2007
    #2
    1. Advertising

  3. How about this code?

    Me.Master.Page.Title = "Whatever"

    --
    I hope this helps,
    Steve C. Orr,
    MCSD, MVP, CSM, ASPInsider
    http://SteveOrr.net


    "Roshawn" <> wrote in message
    news:...
    > 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
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], Jan 9, 2007
    #3
  4. Roshawn

    Roshawn Guest

    Thanks for the reply, Steve. Unfortunately, this doesn't work. :-(
     
    Roshawn, Jan 9, 2007
    #4
  5. Roshawn

    Roshawn Guest

    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.
     
    Roshawn, Jan 9, 2007
    #5
  6. Roshawn

    Roshawn Guest

    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
     
    Roshawn, Jan 9, 2007
    #6
  7. Roshawn

    Mark Rae Guest

    "Roshawn" <> wrote in message
    news:...

    > 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...?
     
    Mark Rae, Jan 9, 2007
    #7
  8. Roshawn

    Roshawn Guest

    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
     
    Roshawn, Jan 9, 2007
    #8
  9. Roshawn

    Mark Rae Guest

    "Roshawn" <> wrote in message
    news:...

    > 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...
     
    Mark Rae, Jan 9, 2007
    #9
  10. Roshawn

    clintonG Guest

    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


    "Mark Rae" <> wrote in message
    news:...
    > "Roshawn" <> wrote in message
    > news:...
    >
    >> 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...
    >
     
    clintonG, Jan 9, 2007
    #10
  11. Roshawn

    Alastair Guest

    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!



    *** Sent via Developersdex http://www.developersdex.com ***
     
    Alastair, Jan 18, 2007
    #11
    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. =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

    set <title> and <meta name='description'> with master page

    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=, Mar 16, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    2,977
    Steven Cheng[MSFT]
    Mar 17, 2006
  2. Laith Zraikat
    Replies:
    3
    Views:
    1,237
    Walter Wang [MSFT]
    Jul 6, 2006
  3. Replies:
    0
    Views:
    554
  4. Replies:
    1
    Views:
    571
    David
    Apr 24, 2007
  5. Chris Walls

    ASP.NET Master Page & Dynamic Page Title

    Chris Walls, Jul 20, 2007, in forum: ASP .Net
    Replies:
    8
    Views:
    1,229
    Chris Walls
    Jul 25, 2007
Loading...

Share This Page