Solved

Retrieve adsense javascript from code behind for asp.net pages

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
C# Offline Apllication 5 48
Regex in JavaScript to validate US phone number with hyphens 3 27
C# parent child form 5 13
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

932 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

11 Experts available now in Live!

Get 1:1 Help Now