title: JQUERY AJAX multiple cascading dropdownlist select does not load problem
body: <p>I am trying to use AJAX Cascading DropDownList using jQuery in ASP.Net. But when I select the first dropdownlist (ddl_il) I can't reach second Dropdownlist with jquery, I am getting the error as a null what is my problem about jquery code? how can I solve it? </p>
  
  <p><img src="https://i.stack.imgur.com/W6xnO.jpg" alt="enter image description here"></p>
  
  <p><br><br><br> <strong>Default.aspx</strong></p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;script src="JS/jquery-1.3.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
          $("#loaderGif1").hide(); 
          $("#loaderGif2").hide();
  
          $("#ddl_ilce").html("&lt;option value=''&gt;Önce İl Seçiniz&lt;/option&gt;");
          $("#ddl_semt").html("&lt;option value=''&gt;Önce İlçe Seçiniz&lt;/option&gt;");
  
          $("#ddl_il").change(function() {
              ilChange();
          })
  
          $("#ddl_ilce").change(function() {
              ilceChange();
          })
      });
  
      function ilChange() {
          $("#loaderGif1").show();
          $("#ddl_ilce").attr("disabled", "true").html("&lt;option value=''&gt;Önce İl Seçiniz&lt;/option&gt;");
          $("#ddl_semt").attr("disabled", "true").html("&lt;option value=''&gt;Önce İlçe Seçiniz&lt;/option&gt;");
  
          var ilID = $("#ddl_il").val();
  
          var pagePath = window.location.pathname;
  
  
  
          $.ajax({
              type: "POST", //GET veya POST
              url: "Default.aspx/ilChange",
              contentType: "application/json; charset=utf-8",
              data: '{ilID:'+ilID+'}', 
              dataType: "json",
              success: onSucceeded1, 
              error: onFailed 
          });
          return false;
      }
  
      //istek başarılı olduğunda çalışacak fonksiyon
      function onSucceeded1(result) {
          $("#loaderGif1").hide();
          $("#ddl_ilce").removeAttr("disabled").html(result.d);
  
          $("#ddl_semt").removeAttr("disabled");
      }
  
      //istek hatalı olduğunda çalışacak fonksiyon
      function onFailed(result) {
          alert(result.d);
      }
  
      function ilceChange() {
          $("#loaderGif2").show();
          $("#ddl_semt").attr("disabled", "true").html("&lt;option value=''&gt;Önce İlçe Seçiniz&lt;/option&gt;");
          var ilceID = $("#ddl_ilce").val();
          var pagePath = window.location.pathname;
  
          $.ajax({
              type: "POST",
              url: "Default.aspx/ilceChange",
              contentType: "application/json; charset=utf-8",
              data: '{ilceID:' + ilceID + '}',
              dataType: "json",
              success: onSucceeded2,
              error: onFailed
          });
          return false;
      }
  
      function onSucceeded2(result) {
          $("#loaderGif2").hide();
          $("#ddl_semt").removeAttr("disabled").html(result.d);
      }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
  
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      il&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:DropDownList ID="ddl_il" runat="server" &gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      ilçe&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:DropDownList ID="ddl_ilce" runat="server" &gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;img id="loaderGif1" alt="" src="Images/loader.gif" style="width: 16px; height: 16px" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      semt&lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:DropDownList ID="ddl_semt" runat="server"&gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;img id="loaderGif2" alt="" src="Images/loader.gif" style="width: 16px; height: 16px" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><BR><BR><br>
  <strong>Default.aspx.cs  Code Behind</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data;
  using System.Data.SqlClient;
  using System.Web.Services;
  
  public partial class _Default : System.Web.UI.Page 
  {
      fonksiyon system = new fonksiyon();
      protected void Page_Load(object sender, EventArgs e)
      {
          SqlConnection baglantim = new SqlConnection("Data Source=Hkadir;Initial Catalog=il-ilce-Semt;Integrated Security=True");
          DataTable dataTableIl = new DataTable();
          SqlCommand sqlCommand = new SqlCommand();
          SqlDataAdapter sqlAdapter = new SqlDataAdapter();
  
          baglantim.Open();
          try
          {
              sqlCommand = new SqlCommand("Select * from iller", baglantim);
  
              sqlAdapter = new SqlDataAdapter(sqlCommand);
              sqlAdapter.Fill(dataTableIl);
  
              ddl_il.DataSource = dataTableIl;
              ddl_il.DataTextField = "Ad";
              ddl_il.DataValueField = "IlID";
              ddl_il.DataBind();
              ListItem li = new ListItem("İl Seçiniz","");
              ddl_il.Items.Insert(0, li);
          }
          finally
          {
              baglantim.Close();
          }
      }
  
  
      public static string ilChange(string ilID)
      {
          System.Threading.Thread.Sleep(2000);
          SqlConnection baglantim = new SqlConnection("Data Source=Hkadir;Initial Catalog=il-ilce-Semt;Integrated Security=True");
          DataTable dataTableIlce = new DataTable();
          SqlCommand sqlCommand = new SqlCommand();
          SqlDataAdapter sqlAdapter = new SqlDataAdapter();
          string result="";
  
          baglantim.Open();
          try
          {
              sqlCommand = new SqlCommand("Select * from ilceler where IlID=@IlID", baglantim);
  
              sqlCommand.Parameters.Add("IlID", SqlDbType.NVarChar);
              sqlCommand.Parameters["IlID"].Value = ilID;
  
              sqlAdapter = new SqlDataAdapter(sqlCommand);
              sqlAdapter.Fill(dataTableIlce);
  
              result += "&lt;option value=''&gt;İlçe Seçiniz&lt;/option&gt;";
              foreach (DataRow dataRow in dataTableIlce.Rows)
              {
                  result += "&lt;option value='" + dataRow["IlceId"].ToString() + "'&gt;" + dataRow["Ad"].ToString() + "&lt;/option&gt;";
              }
              return result;
          }
          catch(Exception e)
          {
              return (e.ToString());
          }
          finally
          {
              baglantim.Close();
          }
      }
  
  
      public static string ilceChange(string ilceID)
      {
          System.Threading.Thread.Sleep(2000);
          SqlConnection baglantim = new SqlConnection("Data Source=Hkadir;Initial Catalog=il-ilce-Semt;Integrated Security=True");
          DataTable dataTableSemt = new DataTable();
          SqlCommand sqlCommand = new SqlCommand();
          SqlDataAdapter sqlAdapter = new SqlDataAdapter();
          string result = "";
  
          baglantim.Open();
          try
          {
              sqlCommand = new SqlCommand("Select * from semtler where IlceID=@IlceID", baglantim);
  
              sqlCommand.Parameters.Add("IlceID", SqlDbType.NVarChar);
              sqlCommand.Parameters["IlceID"].Value = ilceID;
  
              sqlAdapter = new SqlDataAdapter(sqlCommand);
              sqlAdapter.Fill(dataTableSemt);
  
              result += "&lt;option value=''&gt;Semt Seçiniz&lt;/option&gt;";
              foreach (DataRow dataRow in dataTableSemt.Rows)
              {
                  result += "&lt;option value='" + dataRow["SemtId"].ToString() + "'&gt;" + dataRow["Ad"].ToString() + "&lt;/option&gt;";
              }
              return result;
          }
          catch (Exception e)
          {
              return (e.ToString());
          }
          finally
          {
              baglantim.Close();
          }
      }
  }
  </code></pre>
  
  <p><strong>Database :</strong> </p>
  
  <p><img src="https://i.stack.imgur.com/Uxmsx.jpg" alt="enter image description here"></p>