473,581 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to stop ASP.NET inserting another <title> tag in my master psge?

Hello,

I am just experimenting with master pages, and am trying to add a
content placeholder in the <head> section, so that individual pages can
set their own page title and meta tags. The master page looks like
this...

<%@ Master Language="C#" AutoEventWireup ="true"
CodeFile="Maste rPage.master.cs " Inherits="Maste rPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<asp:ContentPla ceHolder ID="cphHead" runat="server" />
</head>
<body>
.... other stuff with content placeholders here...
</body>
</html>

A page that uses this master would have content controls for the
placeholder in the header, as well as the others in the body (not
shown). For example (partial code for a sample .aspx page shown)...

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="About .aspx.cs"
Inherits="About " Title="Untitled Page" debug="true"
MasterPageFile= "MasterPageToys .master" %>
<asp:Content ID="cntHead" ContentPlaceHol derID="cphHead" Runat="Server">
<title>Test Page Using Master Pages</title>
<meta name="keywords" content="stuff, nonsense, master pages, asp.net">
<meta name="descripti on" content="This is a page using master pages,
etc">
</asp:Content>
....other content controls here...

The problem is that when the page is rendered, ASP.NET adds another
<title> tag, giving invalid HTML like this...

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Test Page Using Master Pages</title>
<meta name="keywords" content="stuff, nonsense, master pages, asp.net">
<meta name="descripti on" content="This is a page using master pages,
etc">
<title>
Untitled Page
</title></head>
<body>

Is there any way to stop it doing this, or am I going about this the
wrong way? Any comments appreciated.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
1 1854
>The problem is that when the page is rendered, ASP.NET adds another
<title> tag, giving invalid HTML like this...

<snip>

Since posting, I discovered that the page itself exposes a Title
attribute in the page directive, and the Page object has a corresponding
Title property, so the title can either be set in the .aspx file or in
the code-behind.

However, it seems that setting the meta tags is a lot more work. The
example I showed used a content control with the meta tags in, which is
quick and simple. Doing this programmaticall y looks like this...

HtmlMeta hm1 = new HtmlMeta();
// Get a reference to the page header element.
HtmlHead head = (HtmlHead)Page. Header;
// Define an HTML <meta> element that is useful for search engines.
hm1.Name = "keywords";
hm1.Content = "words that describe your web page";
head.Controls.A dd(hm1);

which is a lot of work for such a simple task!!

So, is there any disadvantage to doing it the way I showed? Even having
a literal control in the .aspx file's content control would be less
lines than the way shown above.

Any comments?

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
14999
by: mark | last post by:
IF I have something like this: <title><?php print($pagetitle); ?></title> <body> <?php include("folders/my_include.php"); ?> </body> </html> and my_include.php contains the value to the variable ($pagetitle). How do I get the value before the code for the <title> is written. This is just a
5
4138
by: Info 3000 | last post by:
Hi there, Simple question, but headache ! I have a PHP Page like : <HTML> <HEAD> <TITLE>Sunny day !</TITLE> </HEAD>
3
10098
by: D. Alvarado | last post by:
Hello, I am trying to find the <TITLE> element of my document. Normally alert(document.title); works just fine, but when this statement is within a page that is a frame in a larger document, the above call always returns the title of the parent (container) page. Is it possible through JS to deduce the <TITLE> element of the current...
1
1396
by: Andreas Klemt | last post by:
Hello, I have in my strHtml a html page. so what is the fastest way (with XML Read?) to get the "myValue" between <title>myValue</title> Thanks, Andreas
6
1932
by: Alex | last post by:
Hi, is it possible to set the title programatically from the code behind page. I placed a literal in the head section of the form and set its text property. it seemed to work bu the literal is not in the <form> section of the page. does this matter or is there a better way to programatically/dynamically set the title of the page.
8
3959
by: DC | last post by:
In HTML page, I put: <html> <head> <title>Article: <asp:Label ID="lblHTMLTitle"></asp:Label> </title> .... In the code behind: ....
7
1583
by: Brad | last post by:
I'm placing a runat=server attribute on the <title> tag in my pages, so I can read/set the title text in code. The problem is that when I subsequently change the page in design view VS is removing the runat=server from the <title> tag. Unfortunately it does not do it all the time...maybe 50%. Brad
4
3814
by: David Thielen | last post by:
Hi; If I am using master pages, how do I set the <title> and <meta name='description' content='my title'> for each page. Obviously each page will have a different title & description. -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com
15
1906
by: Steve B | last post by:
Is there a way to manipulate the <TITLEin the csharp code?
0
7876
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7804
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7910
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.