I have created a sandboxed solution for SharePoint 2010 which contains sandboxed visual webpart. I need to make ajax POST call and pass the entities from javascript. can you tell me how can I accomplish this requirement? How can we load the .aspx page and where will I write the code behind so that I can get the variables passed using ajax POST?

 url: "https://mydomain.com/Sandbox/webservice/page.aspx",
  beforeSend: function (xhr){
         xhr.setRequestHeader('command', 'name');
        type: "POST",
        dataType: "html",
        success:function(){var x=something}
          timeout: 5000

Now my question is how can i load the aspx page and how can i access the entities like "command" from code behind?

2 Answers 2


You put your ajax call in a separate javascript function that takes your parameters as arguments:

function myFunction(command, name){

Then you can call it from your web part by printing out the html to call the function with your arguments passed in. In a standard web part I did it myself like this:

protected override void RenderContents(HtmlTextWriter html)
    html.Write(string.Format("<script>ExecuteOrDelayUntilScriptLoaded(function () {{ myfunction('{0}','{1}') }}, 'sp.js');</script>", myCommand, myName)));

You could accomplish the same with a literalcontrol if you don't use the RenderContents method.

  • Do you have a working sample of the same? actually I am trying to pass the data from javascript(client) to server side using ajax call (POST) method.. The solution which you have told seems to be different from the requierment. Email ID: [email protected]
    – sharmila
    Commented Oct 12, 2012 at 9:43
  • I seem to have misunderstood; from your first post I thought you wanted to pass a variable from your web part to your javascript. You actually want to do the opposite? Commented Oct 12, 2012 at 11:12
  • Yes. i need to pass variables from javascript to server side using ajax call
    – sharmila
    Commented Oct 12, 2012 at 12:00

hi if you are using ajax control tool kit make sure that tool kit is compactable with the SP2010 if its compactable then your ajax codes will work. you can open a visual webpart and add your ajax codes and deploy it into your SP2010 site. then add the webpart.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.