title: dropdownlist values from jquery are not recognized in c# code behind
body: <p>I am trying to get a selected item from asp.net dropdownlist control which is populated from jquery ajax call. I am able to loop through the items on the screen, see the options attached in the source of the page but when I am trying to get the value from the c# backend code I am getting blank value. 
  This is what I have:</p>
  
  <pre><code>   $('#&lt;%=Button2.ClientID %&gt;').click(function () {
                  var Dropdown2 = $('#&lt;%=ddlListAgents.ClientID %&gt;');
                    Dropdown2.empty();
                    $.ajax({
                        type: "POST",
                        url: "WebForm3.aspx/fetchData",
                        data: "{selectedAgent: '" + $('#&lt;%=txtAgentNameText.ClientID %&gt;').val() +"'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            Dropdown2.append(new Option("--Select Agent --", 0));
                            $.each(response.d, function (index, item) {
                                Dropdown2.append(new Option(item.Name, item.ID));
                            });
                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                            alert(xhr.status);
                            alert(thrownError);
                        }
                    });
              });  
  </code></pre>
  
  <p>Everything is set ok after that call and I am able to browse the options. But when I am clicking a button and trying to get the selected value in this code (test code):</p>
  
  <pre><code>protected void btnSelectAgentAdd_ServerClick(object sender, EventArgs e)
          {
              foreach (ListItem item in ddlListAgents.Items)
              {
                  if (item.Selected.Equals(true))
                  {
                      item.Value.ToString();
                  }
                  else
                  {
                      item.Value.ToString();
                  }
              }
              string one = ddlListAgents.SelectedValue;
          }    
  </code></pre>
  
  <p>After the first loop the code steps out from the for loop, and the ddlListAgents.SelectedValue is equal to empty string. </p>
  
  <p>This is the method I am using to get the dataset:</p>
  
  <pre><code>[WebMethod]
  public static List&lt;AgentName&gt; fetchData(string selectedAgent)
  {
      Dictionary&lt;string, string&gt; list = new Dictionary&lt;string, string&gt;();
      BL.Client client = new BL.Client();                              
      var agents = new List&lt;AgentName&gt;();
      if (selectedAgent != string.Empty)
      {
          list = client.GetAgentNamesForPopupSearch(selectedAgent);                   
      }
  
      foreach (KeyValuePair&lt;string, string&gt; val in list)
      {
          agents.Add(new AgentName { ID = Convert.ToInt32(val.Key), Name = val.Value });
      }
      return agents;
  }
  </code></pre>
  
  <p>Every advice is welcome. 
  Thanks in advance, Laziale</p>
  
  <p>EDIT: 
  Page Load event added:</p>
  
  <pre><code>  if (!IsPostBack)
              {
                  Dictionary&lt;string, string&gt; list = new Dictionary&lt;string, string&gt;();
                  BL.Client client = new BL.Client();
                  list = client.GetAgentNamesForPolicies2(Convert.ToInt32(4));
                  ddlAgentName.DataSource = list;
                  ddlAgentName.DataTextField = "Value";
                  ddlAgentName.DataValueField = "Key";
                  ddlAgentName.DataBind();
                  ddlAgentName.Items.Insert(0, new ListItem("-- Select Agent --", string.Empty));            
              }
  </code></pre>