master page generating a second title tag
Asked Answered
R

3

7

I have a simple page inside a master page (well, in a master in a master).

In the top master I have the head tag with runat="server", with a number of bits such as scripts, stylesheets, etc. and also a contentplaceholder. There is no title tag here.

In the page that uses this master, the content for the placeholder contains the <title>pagename</title> bit in it. I really have to set it in there.

Unfortunately when the page is rendered I get my title which is all good, but also get a second blank title tag - I presume dumped in there by .NET.

Is there any way of stopping this second title tag coming out?

Runagate answered 5/1, 2010 at 12:44 Comment(0)
P
17

From memory, by virtue of putting the runat="server" on the <head> .Net automagically adds a <title> if there isn't one already.

I think (haven't tested it) is if in your masterpage you do

<head runat="server">
Blah
<title runat="server" visible="false"></title>
</head>

setting the Title tag explicitly in the Head of the masterpage and setting visibility to false works. I think.

Partnership answered 5/1, 2010 at 13:0 Comment(2)
cunning, didnt try that, although i suspect it would work. ended up adding a seperate contentplaceholder for the title in the top master <title><placeholder here</title> ... works fine thanks anyhowRunagate
I've just had the same problem and tried this fix. I can confirm that it does work. Well done.Discriminating
C
4

You don't have to manually insert <title> to the head.
Just set Page.Title = "title" by code, or <%@ Page Title="My Title" .. %> by markup. ASP.NET will figure out the rest, and put the right title.

Cesar answered 5/1, 2010 at 12:51 Comment(0)
T
1

I think using:

If you want to set title at page level

<%@ Master ... %>
<html>
<head runat="server">
  <title>
    <asp:ContentPlaceHolder ID="titleContent" runat="server" />
  </title>
</head>

Or,

If you want to set dynamic title at Master Page level.

<%@ Master ... %>
<html>
<head runat="server">
  <title>
    <asp:Literal ID="litPageTitle" runat="server"></asp:Literal>
  </title>
</head>

is better way to make sure that empty second title tag is not generated.

Twoup answered 3/5, 2013 at 4:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.