title: Use Ajax and Confirm message for delete
body: <p>I want to get a confirm message on clicking delete ImageButton. If the user selects 'Ok' then delete is done, else if 'Cancel' is clicked nothing happens. </p>
  
  <pre><code>&lt;asp:ImageButton ID="ImageButton1" runat="server"  ImageUrl="~/images/forDesign/delete.png"   OnClientClick="ConfirmDelete()"  /&gt;
  
  &lt;script type="text/JavaScript" 
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      function ConfirmDelete() {
          var x = confirm("Are you sure you want to delete?");
          if (x)
              $.ajax({
                  type: "get",
                  url: "SearchTicket.aspx/Delete",
                  contentType: 'application/json; charset=utf-8',
                  dataType: 'json',
                  success: function (response) {
                      alert(response.status);
                  },
                  error: function () {
                      alert("error");
                  }
              });           
      }
  </code></pre>
  
  <p>  </p>
  
  <p>and in code behind I have:</p>
  
  <pre><code> [WebMethod]
  public void Delete()
  {
      string code = DetailsViewCodeTicket.Rows[2].Cells[1].Text.ToString();
      Ticket.TicketCusDelete(code);
      DetailsViewCodeTicket.DataBind();
  }
  </code></pre>
  
  <p>but when I clicking the ImageButton I get this error:</p>
  
  <p><a href="https://i.stack.imgur.com/agsDX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/agsDX.jpg" alt="enter image description here"></a></p>
  
  <p>How can I do that ?</p>