title: assign C# string of array or string[] to javascript array
body: <p>I have a js code in which an array works well when its like </p>
  
  <pre><code>var availableTags = [
              "ActionScript",
              "AppleScript",
              "Asp",
              "BASIC",
              "C"
                       ];
  </code></pre>
  
  <p>I then made an array string in my code behind or .cs like on class level </p>
  
  <pre><code> public static string[] test={"animal","lovely"};
  </code></pre>
  
  <p>I then changed js array to this </p>
  
  <pre><code> var availableTags =  "&lt;%=test%&gt;"; // also tried without quotes 
  </code></pre>
  
  <p>Now I m not having the results as was having with previous js array </p>
  
  <p><strong>Editing with complete code,the jquery I taken from <a href="http://jqueryui.com/demos/autocomplete/#multiple" rel="noreferrer">http://jqueryui.com/demos/autocomplete/#multiple</a></strong></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.Collections;
  using System.Web.Script.Serialization;
  
  public partial class onecol : System.Web.UI.Page
  {
     JavaScriptSerializer serializer;
  
     public static string test = "['animal','lovely']";
      public static string check;
  
  
      protected void Page_Load(object sender, EventArgs e)
      {
         serializer = new JavaScriptSerializer();
          //serializer
          this.detail.ToolsFile = "BasicTools.xml";
          test = returnTitle();
      }
  
  }
  </code></pre>
  
  <p>and the script with html is </p>
  
  <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"&gt;
  &lt;script type="text/javascript" src="Jscript.js"&gt;&lt;/script&gt;  
       &lt;script type="text/javascript" src="jquery-1.7.1.min.js"&gt;&lt;/script&gt; 
       &lt;script type="text/javascript" src="jquery-ui-1.8.17.custom.css"&gt;&lt;/script&gt;  
       &lt;link href="~/jquery-ui-1.8.17.custom.css" rel="stylesheet" type="text/css"/&gt;
        &lt;script type="text/javascript"&gt;
            $(function () {
                  var availableTags =  &lt;%=test%&gt;;
  
                function split(val) {
                    return val.split(/,\s*/);
                }
                function extractLast(term) {
                    return split(term).pop();
                }
  
                $("#tags")
                // don't navigate away from the field on tab when selecting an item
              .bind("keydown", function (event) {
                  if (event.keyCode === $.ui.keyCode.TAB &amp;&amp;
                          $(this).data("autocomplete").menu.active) {
                      event.preventDefault();
                  }
              })
              .autocomplete({
                  minLength: 0,
                  source: function (request, response) {
                      // delegate back to autocomplete, but extract the last term
                      response($.ui.autocomplete.filter(
                          availableTags, extractLast(request.term)));
                  },
                  focus: function () {
                      // prevent value inserted on focus
                      return false;
                  },
                  select: function (event, ui) {
                      var terms = split(this.value);
                      // remove the current input
                      terms.pop();
                      // add the selected item
                      terms.push(ui.item.value);
                      // add placeholder to get the comma-and-space at the end
                      terms.push("");
                      this.value = terms.join(", ");
                      return false;
                  }
              });
            });
      &lt;/script&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"&gt;
  
  &lt;div class="demo" &gt;
  &lt;div class="ui-widget"&gt;
      &lt;label for="tags"&gt;Tag programming languages: &lt;/label&gt;
      &lt;input id="Text1" class="#tags" size="50" /&gt;
  
  
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>actually its a auto complete functionality to give tags ,the auto complete suggestions for tagging I want to get from C# code ,I took Jquery source from jqueryui.com/demos/autocomplete/#multiple and then I tried to give it C# string from .cs file , I explained it with code on edited version , with C# code behind it works exactly as its in the link</p>