Question

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?

Was it helpful?

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">
........

OTHER TIPS

You have already a head section in there:

<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>

check your project for files, which put content into this PlaceHolder. If you want to define a <head> wrap it around this content placeholder. But then you need to check the contents of the other files and refactor it, so you do not define a head tag inside a head tag.

<!DOCTYPE html>

<html>
<head runat="server">
    <title></title>
    <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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
          <div class="content" id="Content">
             // ...
          </div>
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

You can place the <head runat="server"></head> above the content..

Wich file are you supposed to put in the other?

One is using a masterpagefile and the other isn't.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top