title: Why does my button click execute multiple times?
body: <p>I have written this ajax code to send data to web service asmx. It works but with a single click, it inserts data multiple times and sometimes it takes 2,3 click to insert data. </p>
  
  <p>.js</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
  
              function save()
              {
                  $("button").click
                  (
                       function()
                       {
                          $.post
                          (
                              "http://localhost:82/ws/himher.asmx/InsertUsers",
                              {name: txtUserName.value, pwd: txtUserPwd.value},
  //                          
                          );
  
                       }
                  );
              }
  
  
  
          &lt;/script&gt;
      &lt;/head&gt;
  &lt;body&gt; 
      &lt;div class="container-fluid"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                   &lt;label&gt;User Name&lt;/label&gt;
                   &lt;input id="txtUserName" type="text" class="form-control" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                   &lt;label&gt;Password&lt;/label&gt;
                   &lt;input id="txtUserPwd" type="text" class="form-control" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;    
          &lt;br/&gt;
           &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;     
                   &lt;button type="submit" onclick='save()' class="btn btn-primary pull-right"&gt;Register&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;    
      &lt;/div&gt;
  </code></pre>
  
  <p>.cs:</p>
  
  <pre><code>public class himher : System.Web.Services.WebService
  {
  
      [WebMethod(EnableSession = true)]
      //[ScriptMethod(UseHttpGet = false)]
      public string InsertUsers(string name, string pwd)
      {
          try
          {
              basicoperation bop = new basicoperation();
              return bop.insertUsers(name, pwd);
          }
          catch (Exception ex)
          {
  
              throw ex;
          }
  
  
      }
  
  
      public string insertUsers(string Name, string Password)
      {
              string status;
  
              String ConStr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
  
              SqlConnection sqlCon = new SqlConnection(ConStr);    // to make a connection with DB 
  
              SqlCommand sqlCom = new SqlCommand("InsertUsers", sqlCon); // now in order to perform action such as insert SP, we must create command object which needs command name and conncetion only
  
              sqlCom.CommandType = CommandType.StoredProcedure;  // you must tell the system that insertInfo is a storedprocedure 
  
              SqlParameter sqlParamName = new SqlParameter("@UserName", Name);
              SqlParameter sqlParamPwd= new SqlParameter("@Password", Password);
  
              sqlCom.Parameters.Add(sqlParamName);
              sqlCom.Parameters.Add(sqlParamPwd);      
  
              try
              {
                  sqlCon.Open();
  
                 int i= sqlCom.ExecuteNonQuery();   // executenonquery is used for INSERT, UPDATE, DELETE 
  
                  //sqlCom.ExecuteScalar();   // used to pick or read a single value from procedure
                 // Response.Write("Done");
  
                  sqlCon.Close();
  
                  status= "Success";
              }
              catch (Exception ex)
              {
                  //response.Write(ex.Message);
                  status = ex.Message;
              }
          return status;
      }
  }
  </code></pre>