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 !!!!!!

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);  
    }

}
Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.