SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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: "",
  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?

share|improve this question

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.

share|improve this answer
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: – sharmila Oct 12 '12 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? – Spongeroberto Squarepantalones Oct 12 '12 at 11:12
Yes. i need to pass variables from javascript to server side using ajax call – sharmila Oct 12 '12 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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