Transfering javascript on content page

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 3
Reputation: piote is an unknown quantity at this point 
Solved Threads: 0
piote piote is offline Offline
Newbie Poster

Transfering javascript on content page

 
0
  #1
Oct 17th, 2007
Hi,

I have the following javascript:


  1. <script language="javascript" type="text/javascript">
  2.  
  3. // Global variables.
  4. var numSeconds;
  5. var timerId = null;
  6. var timerInterval = 1000;
  7. var numUpdates = 0;
  8.  
  9. // Handle OnLoad event.
  10. window.onload = Window_OnLoad;
  11.  
  12. function Window_OnLoad()
  13. {
  14. StartProcess();
  15. }
  16.  
  17. // Starts the process for updating the Map.
  18. function StartProcess()
  19. {
  20. // 200 x 3 seconds = 600 seconds = 10 minutes demo.
  21. if ( numUpdates < 72 )
  22. {
  23. // Duration between actual updates to the map in seconds.
  24. numSeconds = 3;
  25. UpdateMap();
  26. numUpdates++;
  27. }
  28. }
  29.  
  30. // Continues the process of updating the Map.
  31. function UpdateMap()
  32. {
  33. if ( numSeconds == 0 )
  34. {
  35. // Clears the timer.
  36. clearTimeout(timerId);
  37.  
  38. // Update the Map control.
  39. var mapControl = document.getElementById("MapControl1");
  40. mapControl.doCallback("IncrementSales", "");
  41.  
  42. // Restart the process.
  43. StartProcess();
  44. }
  45. else
  46. {
  47. // Decrease the value for seconds.
  48. numSeconds = numSeconds - 1;
  49.  
  50. // Continue the delayed process.
  51. timerId = self.setTimeout("UpdateMap()", timerInterval);
  52. }
  53. }
  54. </script>



It works fine, when used on a standalone page, but when I am using masterpage and contentpages and I paste it into my content page (between <asp:content> and </asp:content> tags) it does not work. I'm a newbie at javascripts and I assume that there is something simple to correct. Could you please help me to make this script work under my content page?



Regards,

Piote
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Transfering javascript on content page

 
0
  #2
Oct 17th, 2007
This is probably to do with how the javascript is rendered (somewhere in the middle) in the completed page that goes to the browser.

I would put the javascript in a .js file. Then in the page_load event of the content page you can get a reference to the master (can't recall syntax off the top of my head but it's something like: Page.Master) then attach a script block using Master.ClientRegisterScriptBlock where the Src property is the relative path to the .js file.

Sorry I can't give exact code this very moment, If I get a chance I will post it.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC