transfer data from an asp .net page into a javasscript script

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

Join Date: Jul 2006
Posts: 2
Reputation: sergiofmolina is an unknown quantity at this point 
Solved Threads: 0
sergiofmolina sergiofmolina is offline Offline
Newbie Poster

transfer data from an asp .net page into a javasscript script

 
0
  #1
Jul 28th, 2006
Hello, I am new at this forum. I am trying to figure out how, if possible at all, to transfer data from an asp .net page into a javascript script in an HTML page.
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: transfer data from an asp .net page into a javasscript script

 
0
  #2
Jul 28th, 2006
  1. string script = "<script type=\"text\\javascript\">function(){alert('some data');};</script>";
  2. Page.RegisterClientScriptBlock("myscript", script);

That's an easy way. There are many others like AJAX google for that.
Last edited by hollystyles; Jul 28th, 2006 at 1:15 pm.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 2
Reputation: sergiofmolina is an unknown quantity at this point 
Solved Threads: 0
sergiofmolina sergiofmolina is offline Offline
Newbie Poster

Re: transfer data from an asp .net page into a javasscript script

 
0
  #3
Aug 1st, 2006
Thanks hollystyles, I tried the code and did not work. It seems that this code works when the script and the data are in the same page. I have the script in an html page different to the asp page.
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: transfer data from an asp .net page into a javasscript script

 
0
  #4
Aug 2nd, 2006
There is more than one way to register the script. Maybe RegisterStartupScript may work better as it waits till the page is fully loaded in the browser before firing. Also I had my slash the wrong way around in the "text/javascript" attribute of the script tags.

HTML Page:

[HTML]<html>
<head>
<script type="text/javascript">
function myFunction(data)
{
alert(data);
}
</script>
</head>
<body>
</body>
</html>[/HTML]

ASP.NET page

  1. string data = "Hello!";
  2.  
  3. string script = "<script type=\"text/javascript\">";
  4. script += "myFunction('" + data + "');</script>";
  5. Page.RegisterStartupScript("myscript", script);
Last edited by hollystyles; Aug 2nd, 2006 at 10:17 am.
==========================================
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