title: Passing Javascript Array to C# Code Behind using Ajax POST
body: <p>I am trying pass javascript array to C# code behind using ajax post back. but When I try this It didn't work. I have attached My code below. Can any one please help me on this??</p>
  
  <p>test.aspx</p>
  
  <pre><code> &lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="hotelbeds.test" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
  &lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8" /&gt;
  &lt;title&gt;jQuery UI Tooltip - Custom animation demo&lt;/title&gt;
  &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /&gt;
  &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt;
  &lt;script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="/resources/demos/style.css" /&gt;
  &lt;script type="text/javascript"&gt;
      function testbook(hotelcode) {
          alert("clicked");
          //var values = {"1","2","3"};
          var mycars = new Array();
          mycars[0] = "Saab";
          mycars[1] = "Volvo";
          mycars[2] = "BMW";
          var theIds = JSON.stringify(mycars);
          alert(theIds);
          $.ajax({
              type: "POST",
              url: "test.aspx/Done",
              contentType: "application/json; charset=utf-8",
              data: "{ 'ids':'"+ theIds +"'}",
           dataType: "json",
           success: function (result) {
               alert('Yay! It worked!');               
           },
           error: function (result) {
               alert('Oh no :(');
           }
          });
  
  
          return false;
  
      }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
  
      &lt;div&gt;
  
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Code Behind File</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data.SqlClient;
  using System.Web.Services;
  using System.Configuration;
  using System.Drawing;
  
  namespace hotelbeds
  {
  
      public partial class test : System.Web.UI.Page
      {
  
          protected void Page_Load(object sender, EventArgs ea)
          {
              ImageButton testbtn = new ImageButton();
              testbtn.OnClientClick = "return testbook('15000')";
              form1.Controls.Add(testbtn);
  
          }
  
          [WebMethod]
          public static void done(string[] ids)
          {
              String[] a = ids;
  
          }
  
  
      }
  }
  </code></pre>
  
  <p>When I change the webmethod as below It worked without any issue. but It's not usefull for me.</p>
  
  <pre><code>  [WebMethod]
          public static void done(string ids)
          {
              String a = ids;
  
          }
  </code></pre>