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
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
Sritharan M
Oh my God Jose, Thanks a lot, this is a very important piece of code for my project. Thanks once again :)
default