Solved

Retrieve adsense javascript from code behind for asp.net pages

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…

737 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