adding <head> tag in an aspx file which has no <head> tag (aim is to put google analytics, adsense)

Posted on 2012-09-11
Last Modified: 2012-09-14
Hi there;

I have several aspx files and need to add google analytics and sense code. According to intel, I need to put those in between <head></head> tags.

The problem is that my aspx files have no <head> tag.

Which line numbers should i put the <head> tags in both examples?

//Ex 1:
<%@ Page Title="" Language="C#" MasterPageFile="~/main.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager ID="smBlatte" runat="server">
    <div id="fb-root">
    <script>        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); = id;
            js.src = "//";
            fjs.parentNode.insertBefore(js, fjs);
        } (document, 'script', 'facebook-jssdk'));
    <div class="wrapper">
        <div class="container">
            <div class="content">
                <div id="featured_slide">
                    <ul id="featurednews">
                        <asp:PlaceHolder ID="phFeaturedNews" runat="server"></asp:PlaceHolder>
//Ex 2:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="MasterPage.master"
    CodeFile="ManageCategory.aspx.cs" Inherits="Admin_ManageCategory" Theme="default" %>

<%@ Register Src="~/Category/Category.ascx" TagName="Category" TagPrefix="uc" %>
<asp:Content ID="ContentChild" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <script type="text/javascript">
        document.getElementById("menuCategory").className = "active";    
    <uc:Category ID="Category1" runat="server" />

Open in new window

Question by:jazzIIIlove
    LVL 14

    Accepted Solution

    Should be in your main.master file...  Take a look and see if thats where it resides.  Here is a decent article that should be able to help you further:
    LVL 26

    Assisted Solution

    by:Alan Warren
    Your masterpage.master should have a head section, it appears as if ContentPlaceHolder1 is in the head section as that is the place your child pages are using to add javascript.

    So I'd suggest putting it in the child pages ContentPlaceHolderID="ContentPlaceHolder1" section, but you would have to put it in every child page manually.

    A better way would be to put it in your ~/main.master page, then all pages will inherit the analytics script.

      <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
        (function() {
          var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
          ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
          var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    <!-- End Head -->

    Open in new window


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now