[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Retrieve adsense javascript from code behind for asp.net pages

Posted on 2011-09-15
1
Medium Priority
?
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 12

Accepted Solution

by:
jagssidurala earned 1500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

656 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