0

Hi I have a ASPX page like this:

<head>
 <title>Sample</title>
 <script src="/javascript/jquery-1.11.1.js"></script>
 <script src="/javascript/angular.js"></script>
 <script src="/javascript/jquery-ui.js"></script>
 <script type="text/javascript">
 function myFunction(message) {
 var stock = new Object();
 stock.symbol = message;
 $.ajax({
 url: '/experiments/Week11/Buy_Experiment1.aspx/BuyStock',
 data: stock,
 error: function () {
 $('#info').html('<p>An error has occurred</p>');
 },
 dataType: 'json',
 success: function (data) {
 console.log(data);
 },
 type: 'POST'
 });
 }
 </script>
</head>

And this is my code behind,

public partial class sample : System.Web.UI.Page
 {
 protected void Page_Load(object sender, EventArgs e)
 {
 ScriptManager.RegisterStartupScript(this, GetType(), "YHOO", "myFunction();", true); 
 }
 }

I am able to successfully call the JQUERY from code behind, but my concern is to send the data "YHOO" from the C# code-ScriptManager to the myFunction javascript variable "message" such that i can send the data "message" as a post data to my backend Web services. Please help !!!!!!

asked Nov 26, 2014 at 21:51

1 Answer 1

1

Try this:

public partial class sample : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {
 ScriptManager.RegisterStartupScript(this, GetType(), "YHOO", "myFunction('YHOO');", true); 
 }
}
answered Nov 26, 2014 at 21:56

1 Comment

Oh my God Jose, Thanks a lot, this is a very important piece of code for my project. Thanks once again :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.