Add Google AdSense javascript code at runtime

S

shapper

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
 
K

Ken Cox [Microsoft MVP]

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]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top