SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting inline JavaScript in ASP.NET

    Hi - I'm trying to insert a simple piece of Google Analytics tracking code into a .NET template which appears when a lightbox style shopping basket feature is triggered.

    However, if I enter the following code into the template it simply does not appear - I just get whitespace:

    Code JavaScript:
    <script type="text/javascript">
    pageTracker._trackPageview("/addtobag/");
    </script>

    I'm a complete .NET novice, in fact I know less than that. I'd just like to understand why this doesn't display.

    Thanks!

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,634
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Can you post a more complete snippet? The important part is probably outside your code.

  3. #3
    SitePoint Member
    Join Date
    May 2011
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for replying, please see below:

    Code:
    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Tenthtime.Models.Product>" %>
    <div class="padding">
    
    <script type="text/javascript">
    pageTracker._trackPageview("/addtobag/");
    </script>
    
        <div id='product_write_logo' style="float:none">
            <%= MerchantLogoHelper.GenerateLogo(Model.GetMerchant(), ViewContext) %>
        </div>
        <p>You have just added this product to your shopping bag.</p>
        <div id="with_border">
            <table cellpadding="10">
                <tr valign="middle">
                    
                    <td> <img src="<%= Model.ThumbUrl %>" /></td>
                    <td>
                        <div class="pr_title">
                            <%= Html.Encode( Model.EncodedName) %>
                        </div>
                        <div class="pr_price">
                            <%= Model.Price %>
                        </div>
                    </td>
                </tr>
            </table> 
        </div>
        <p>
            You can continue browsing our web site or go straight to <b class="pr_title"><%= Model.GetMerchant().Title %></b> to complete your purchase.
        </p>
    </div>
    <div id="continue_browsing">
        <table width="100%">
            <tr>
                <td align='left'  style="padding-left:5px;">
                     <a href="#" onclick="disablePopup(); return false;">Continue Browsing</a> 
                </td>
                <td align="right" style="padding-right:5px;"> 
                    <a target="_blank" href="<%= Url.Action("Buy", "Transition", new{ProductId = Model.Id}) %>" style="float:right" class="buy_now" rel="nofollow"></a> 
                </td>
            </tr>
        </table>
    </div>

  4. #4
    SitePoint Member
    Join Date
    May 2011
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any ideas?

  5. #5
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tenth Time View Post
    Thanks for replying, please see below:

    Code:
    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Tenthtime.Models.Product>" %>
    <div class="padding">
    
    <script type="text/javascript">
    pageTracker._trackPageview("/addtobag/");
    </script>
    
        <div id='product_write_logo' style="float:none">
            <%= MerchantLogoHelper.GenerateLogo(Model.GetMerchant(), ViewContext) %>
        </div>
        <p>You have just added this product to your shopping bag.</p>
        <div id="with_border">
            <table cellpadding="10">
                <tr valign="middle">
                    
                    <td> <img src="<%= Model.ThumbUrl %>" /></td>
                    <td>
                        <div class="pr_title">
                            <%= Html.Encode( Model.EncodedName) %>
                        </div>
                        <div class="pr_price">
                            <%= Model.Price %>
                        </div>
                    </td>
                </tr>
            </table> 
        </div>
        <p>
            You can continue browsing our web site or go straight to <b class="pr_title"><%= Model.GetMerchant().Title %></b> to complete your purchase.
        </p>
    </div>
    <div id="continue_browsing">
        <table width="100%">
            <tr>
                <td align='left'  style="padding-left:5px;">
                     <a href="#" onclick="disablePopup(); return false;">Continue Browsing</a> 
                </td>
                <td align="right" style="padding-right:5px;"> 
                    <a target="_blank" href="<%= Url.Action("Buy", "Transition", new{ProductId = Model.Id}) %>" style="float:right" class="buy_now" rel="nofollow"></a> 
                </td>
            </tr>
        </table>
    </div>
    Wouldn't this work? Or, maybe put it at the bottom of the page?

    Code JavaScript:
     
    <%= Html.Decode(<javascript type="text/javascript">pageTracker._trackPageview("/addtobag/");</javascript) %>

    Probably wrong though...
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  6. #6
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,634
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Not sure exactly what is going wrong here, but you are doing it wrong -- you should wrap the trackPageView call in the client-scripty bits of whatever is adding to the cart, not try and spit it out. Javascript might be interperted, but it ain't that interperted.

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its too small and no functions are described
    insert full code


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •