Why doesn't ASP.NET close the meta tag defined in my MasterPage?

Posted on 2009-02-09
Last Modified: 2012-05-06
I have a MasterPage that starts off as shown below.  As you can see, the meta tag is closed.  But, when a page that references the MasterPage is rendered, the metatag is open thus causing an HTML validation error.  What must I do to get ASP.NET to render the meta tag closed?
<%@ master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage1.Master.cs"

    Inherits="MyCompany.MyApp.MasterPage1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<!-- Copyright 1999-2009, MyCompany Corporation, all rights reserved, -->

<html xmlns="">

<head runat="server">

    <title>MyCompany/MyApp: My System</title>

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

    <link href="~/Styles/styles.css" rel="stylesheet" type="text/css" runat="server" />

    <asp:contentplaceholder ID="head" runat="server">




Open in new window

Question by:carlkelley
    LVL 6

    Accepted Solution

    Usually this has to be done programmatically but you can save yourself a little bit of a headache by placing it within another content placeholder.
    <asp:ContentPlaceHolder ID="MyMetaData" ruat="server">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

    Open in new window


    Author Closing Comment

    Thanks, Ramone.  I did not know that one could add content to a placeholder inside a MasterPage.  If you feel like explaining why this works, I'd like to know.
    LVL 6

    Expert Comment

    The reason you want to place conten within the content place holder within the masterpage is if you want something to be static amongst all pages, just like your meta data.  You also might want to do this if you've created a web user control as a side bar that you want to show up on every page.

    Author Comment

    I appreciate that you answered my question after all points were awarded.  What is puzzling me is this:  Everything OUTside the placeholders in a MasterPage is shared between the pages that inherit the MasterPage.  Why is there a need to put shared content INside the placeholders in a MasterPage?  And why is shared content placed inside placeholders rendered differently than outside content?

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
    In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
    In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now