944,059 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 3226
  • ASP.NET RSS
Jul 28th, 2006
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sergiofmolina is offline Offline
2 posts
since Jul 2006
Jul 28th, 2006
0

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

ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Aug 1st, 2006
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sergiofmolina is offline Offline
2 posts
since Jul 2006
Aug 2nd, 2006
0

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

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

ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Less than a beginner!
Next Thread in ASP.NET Forum Timeline: Dynamically Adding Fields to a DetailsView





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC