Solved

Retrieve adsense javascript from code behind for asp.net pages

Posted on 2011-09-15
1
239 Views
Last Modified: 2012-05-12
I have searched for the last 2 days. I have found a method that will allow me to put my adsense javascript into a .js file then call the file into the page. That will not work for my situation as I need to change one of the variables in the JS progmatically.

I think the ClientScriptManager class is going to have what I am looking for I just cant find it yet. I have looked into RegisterStartupScript, but cant find a solution.

I would be happy if I could just create a string that could be attached to a literal, but the javascript has too many " > < to make that a working solution.

Any ideas?

Here is my adsense javascript


 
<script type="text/javascript"><!--
        google_adtest = "on";
        google_ad_client = "ca-pub-000000000000000";
        /* BlueRectangle */
        google_ad_slot = "XXXXXXXXXX";
        google_ad_width = 336;
        google_ad_height = 280;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>

Open in new window

0
Comment
Question by:DotNetChano
1 Comment
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
ID: 36545457
You can access a variable in JS file.

1) You need a Public variable in .aspx.cs page. Let say

Public string strAdSense;

2) also need to public js variable in .aspx

<script>
var strAdSense = '<%=strAdSense%>'
</script>

3) you can access this 'strAdSense' in .JS file

This JS variable sets in page load only.

If you want you can change the variable using Page.Registerstartupscript by calling below .Js function.

function fncSetAsSense(str)
{
 strAdSense = str;
}

0

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

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

830 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