title: How to pass Dictionary<string, string> variable from code behind to asp.net?
body: <p>Im trying to pass public dictionary from c# to asp.net.</p>
  
  <p>Here's my code:</p>
  
  <p>Code Behind:</p>
  
  <pre><code>public Dictionary&lt;string, List&lt;string&gt;&gt; dict = new Dictionary&lt;string, List&lt;string&gt;&gt;();
  
      protected void Page_Load(object sender, EventArgs e)
      {
  
          if (!IsPostBack)
          {
            RetrieveDataField();
          }
      }
  
   void RetrieveDataField()
  {
  
      DataDefinitionResponse[] _dr = _service.DataDefinitionList(_companyID);
  
      DataTable dt = new DataTable();
      dt.Columns.Add("Name");
      dt.Columns.Add("Type");
  
      foreach (DataDefinitionResponse dr in _dr)
      {
          if (dr.Type != "Group" &amp;&amp; dr.Type != "File")
          {
              DataRow row = dt.NewRow();
              row["Name"] = dr.Name;
              row["Type"] = dr.Type;
              dt.Rows.Add(row);
              if (dr.Type == "Dropdown")
              {
                  string[] strSplit = dr.ListValue.Split('|');
                  List&lt;string&gt; lst = new List&lt;string&gt;();
  
                  foreach (string word in strSplit)
                  {
                      lst.Add(word);
                  }
                  dict.Add(dr.Name, lst);
              }
          }
      }
  
      ddlFieldName.DataSource = dt;
      ddlFieldName.DataTextField = "Name";
      ddlFieldName.DataValueField = "Type";
      ddlFieldName.DataBind();
  
  
  }
  </code></pre>
  
  <p>ASP:</p>
  
  <pre><code>&lt;script  type="text/javascript"&gt;
      $(document).ready(function () {
  
          alert(&lt;%=dict%&gt;); //Error here
          $("#MainContent_ddlFieldName").live("change", function () {
              $.ajax({
                  type: "POST",
                  url: "WebService/WebFunction.asmx/PopulateDropdown",
                  data: "{'dict': '" + 'a' + "'}",
                  contentType: 'application/json; charset=utf-8',
                  dataType: 'json',
                  success: function (data) {
                     // data.d;
                      // $("#txtBLShipperContactNo").val(data.d);
                      alert(data.d);
  
                  },
                  error: function (XMLHttpRequest, textStatus, errorThrown) {
                      alert("Error Shipper: " + errorThrown);
                  }
              });
  
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Any thoughts?</p>