472,955 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,955 software developers and data experts.

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="MasterPage.master.cs" Inherits="MasterPage" %>

<!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:ContentPlaceHolder 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" ContentPlaceHolderID="cphHead" Runat="Server">
<title>Test Page Using Master Pages</title>
<meta name="keywords" content="stuff, nonsense, master pages, asp.net">
<meta name="description" 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="description" 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 1817
>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 programmatically 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.Add(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
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...
5
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
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,...
1
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
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...
8
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
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...
4
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. --...
15
by: Steve B | last post by:
Is there a way to manipulate the <TITLEin the csharp code?
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.