Add Google AdSense javascript code at runtime

Discussion in 'ASP .Net' started by shapper, Oct 3, 2006.

  1. shapper

    shapper Guest

    Hello,

    I need to place Javascript code inside an Asp:panel so that the Google
    Adsense banner be placed inside the panel.

    I know how to do something like this in a page:

    ' Add javascript file (Show_Ads.js) [Google AdSense]
    If Not Page.ClientScript.IsClientScriptIncludeRegistered("AdSense")
    Then
    Page.ClientScript.RegisterClientScriptInclude(Me.GetType(),
    "AdSense", "http://pagead2.googlesyndication.com/pagead/show_ads.js")
    End If

    ' Add javascript code (AdSense Code) [Google AdSense]
    Dim urchinTracker As String = "<script
    type=""text/javascript""><!-- " & _
    "google_ad_client = ""xxx"";" & _
    "google_ad_width = 250;" & _
    "google_ad_height = 250;" & _
    "google_ad_format = ""250x250_as"";"
    & _
    "google_ad_type = ""image"";" & _
    "google_ad_channel ="""";" & _
    "//--></script>"

    If (Not
    Page.ClientScript.IsClientScriptBlockRegistered("AdSenseCode")) Then
    Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
    "AdSenseCode", urchinTracker)
    End If


    However I have no idea of how to place the javascript code inside the
    Asp:panel so that the banner appear there.

    I need to make this at runtime.

    Could somebody help me out with this?

    Thanks,

    Miguel
    shapper, Oct 3, 2006
    #1
    1. Advertising

  2. You could drop a literal control inside the panel and then at runtime set
    the Text property of the literal to urchinTracker or whatever the string is.

    Let us know if this helps?

    Ken
    Microsoft MVP [ASP.NET]

    "shapper" <> wrote in message
    news:...
    > Hello,
    >
    > I need to place Javascript code inside an Asp:panel so that the Google
    > Adsense banner be placed inside the panel.
    >
    > I know how to do something like this in a page:
    >
    > ' Add javascript file (Show_Ads.js) [Google AdSense]
    > If Not Page.ClientScript.IsClientScriptIncludeRegistered("AdSense")
    > Then
    > Page.ClientScript.RegisterClientScriptInclude(Me.GetType(),
    > "AdSense", "http://pagead2.googlesyndication.com/pagead/show_ads.js")
    > End If
    >
    > ' Add javascript code (AdSense Code) [Google AdSense]
    > Dim urchinTracker As String = "<script
    > type=""text/javascript""><!-- " & _
    > "google_ad_client = ""xxx"";" & _
    > "google_ad_width = 250;" & _
    > "google_ad_height = 250;" & _
    > "google_ad_format = ""250x250_as"";"
    > & _
    > "google_ad_type = ""image"";" & _
    > "google_ad_channel ="""";" & _
    > "//--></script>"
    >
    > If (Not
    > Page.ClientScript.IsClientScriptBlockRegistered("AdSenseCode")) Then
    > Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
    > "AdSenseCode", urchinTracker)
    > End If
    >
    >
    > However I have no idea of how to place the javascript code inside the
    > Asp:panel so that the banner appear there.
    >
    > I need to make this at runtime.
    >
    > Could somebody help me out with this?
    >
    > Thanks,
    >
    > Miguel
    >
    Ken Cox [Microsoft MVP], Oct 3, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trevor

    Google Announces Adsense

    Trevor, Jun 24, 2003, in forum: HTML
    Replies:
    5
    Views:
    922
    Jerry Muelver
    Jun 26, 2003
  2. John D.

    Google - adsense

    John D., May 14, 2004, in forum: HTML
    Replies:
    6
    Views:
    488
    Denis McMahon
    Dec 30, 2012
  3. Looking
    Replies:
    15
    Views:
    966
  4. Roedy Green

    fixing Google AdSense

    Roedy Green, Jan 21, 2006, in forum: Javascript
    Replies:
    12
    Views:
    261
    Jim Ley
    Jan 21, 2006
  5. Dr. Clue
    Replies:
    4
    Views:
    118
    Bill H
    Aug 27, 2007
Loading...

Share This Page