title: Alert box by using WebMethod return with Message
body: <p>I want to show an <strong>Alert Message Box When Selected Date is Match with Database Date</strong> on datetime picker.</p>
  
  <p>Even though WebMethod is working fine, my code right now is everytime I select, alert message always come out without checking.</p>
  
  <p>Test.aspx.cs  </p>
  
  <pre><code>    [System.Web.Services.WebMethod]
       public static string GetDateFromDB(DateTime compareDate)  
      {
          string selectedDate = compareDate.ToString("yyyy/MM/dd");
  
          SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LoginDBConnectionString1"].ConnectionString);
          SqlCommand com = new SqlCommand("SELECT * from Holiday where Date='" + selectedDate + "'", conn);
          SqlDataAdapter sqlDa = new SqlDataAdapter(com);
          DataTable dt = new DataTable();
          sqlDa.Fill(dt);
  
          if (dt == null || dt.Rows.Count == 0)
               return "NG";               
          else
              return "OK";
      }
  </code></pre>
  
  <p>Test.aspx</p>
  
  <pre><code>      &lt;link href="http://code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" /&gt;
                  &lt;input type='text' class='date' id="datepicker" autocomplete="off"&gt;
                  &lt;script src="http://code.jquery.com/jquery-1.8.3.min.js"&gt;&lt;/script&gt;
                  &lt;script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"&gt;&lt;/script&gt;
                  &lt;script&gt;
                      jQuery(function ($) {
  
                          $("#datepicker").datepicker({
                              onSelect: function (dateText) {                                    
                                  alert("Selected date: " + dateText + "; input's current value: " + this.value);
                                  $(this).change();
                                  $.ajax({
                                      type: "POST",
                                      url: "Test.aspx/GetDateFromDB",
                                      data: '{ "compareDate" : "' + dateText + '"}',
                                      contentType: "application/json; charset=utf-8",
                                      dataType: "json",
                                      //success: OnSuccess,
                                      //failure: function (response) {
                                      //    alert(response.d);
                                      //}
                                  });
                              },
                            }
                          ).on("change", function () {
                              display("Got change event from field");
                          });
  
                      function display(msg) {
                          $("&lt;p&gt;").html(msg).appendTo(document.body);
                      }
  
                      });
                  &lt;/script&gt;
  </code></pre>