Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2012-09-11
Medium Priority
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); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
            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

binaryevo earned 1000 total points
ID: 38389341
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
Alan Warren earned 1000 total points
ID: 38389546
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') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

<!-- End Head -->

Open in new window


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

564 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