Solved

Retrieve adsense javascript from code behind for asp.net pages

Posted on 2011-09-15
1
231 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now