Search code examples
c#asp.nethtml-head

Where to put the <head> tag in an ASP.NET solution?


I have an ASP.NET project whose page starts with:

<head runat="server">
    <meta charset="utf-8">
    <title>Online SMS Choose</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <link id="Link1" rel="stylesheet" runat="server" media="screen" href="~/css/tableStyle.css" />
    <link id="Link2" rel="stylesheet" runat="server" media="screen" href="~/css/LoadingStyle.css" />
    <link id="Link3" rel="stylesheet" runat="server" media="screen" href="~/css/selectStyle.css" />
    <script src="//code.jquery.com/jquery-1.9.1.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script>
        $(function () {
            $("#tabs").tabs();
        });
        $(function () {
            $("#datepicker").datepicker();
        });

    </script>
</head>

Then my manager told me that I have to merge that project with another one. She gave me the code of the other project. That code doesn't have a head tag in it, but it has this at the start of the page:

<%@ Page Title="Service Categories" Language="C#" MasterPageFile="~/Site.master"
    AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="service._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/javascript" src="Scripts/ZeroClipboard.js"></script>
    <script type="text/javascript" src="Scripts/main.js"></script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <div class="content" id="Content">

Where do I put the <head> tag in this new project?


Solution

  • The first code snippet you provided is standard HTML markup and the second is ASP.NET markup as I am sure you are aware.

    You can combine both of them in the following manner:

    <%@ Page Title="Service Categories" Language="C#" MasterPageFile="~/Site.master"
        AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="service._Default" %>
    
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
        <script type="text/javascript" src="Scripts/ZeroClipboard.js"></script>
        <script type="text/javascript" src="Scripts/main.js"></script>
    
    
        <title>Online SMS Choose</title>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
        <link id="Link1" rel="stylesheet" runat="server" media="screen" href="~/css/tableStyle.css" />
        <link id="Link2" rel="stylesheet" runat="server" media="screen" href="~/css/LoadingStyle.css" />
        <link id="Link3" rel="stylesheet" runat="server" media="screen" href="~/css/selectStyle.css" />
        <script src="//code.jquery.com/jquery-1.9.1.js"></script>
        <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
        <link rel="stylesheet" href="/resources/demos/style.css">
        <script>
            $(function () {
                $("#tabs").tabs();
            });
            $(function () {
                $("#datepicker").datepicker();
            });
    
        </script>
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <div class="content" id="Content">
    ........