title: Object reference is required for the nonstatic field method or property
body: <p>I'm using a C# aspx web form with a WebMethod but I have a problem trying to call a class with public methods, I get this error message:</p>
  
  <blockquote>
    <p>an object reference is required for the nonstatic field method or property.</p>
  </blockquote>
  
  <p>Here is an example of my code.</p>
  
  <p><strong>DB_Class</strong></p>
  
  <pre><code>public int Cuenta(User us, int opcion)
  {
      string sql = "";
      int res = 0;
  
      switch (opcion)
      {
          //Insert
          case 1:
              sql = "query...";
              break;
              //Update
          case 2:
              sql = "";
              break;
              //Delete
          case 3:
              sql = "";
              break;
      }
      //More code, using executenonquery etc. there is no problem with that.
      return res;
  }
  </code></pre>
  
  <p><strong>ASPX, Webmethod code</strong></p>
  
  <pre><code>db_Class conn = new db_Class();
  
  [WebMethod]
  public static string RegistrarCuenta(int id, string usuario, string nombre, string apellido, string email, string password, string fechaNacimiento, int tipo, int op)
  {
      string respuesta = "Ha Ocurrido Un error.";
  
      try
      {
          User us = new User(id, usuario, nombre, apellido, email, password, fechaNacimiento, tipo);
          //I get the error here.
          int resp = conn.Cuenta(us, op);
  
          if (resp &gt; 0)
              respuesta = "Operacion Realizada Correctamente.";
      }
      catch (Exception ex)
      {
          respuesta = "Ha Ocurrido un error: " + ex.Message;
      }
  
      return respuesta;
  }
  </code></pre>
  
  <p>I look here for solutions but I dont found anything like my problem (trying to call a method in another class). Also I tried to change my webmethod to public string intead of public static string but with this now I get this browser error: Unknown web method, I dont know if this problem is for a bad url reference in my ajax code, here is my <strong>ajax</strong> code:</p>
  
  <pre><code> $.ajax({
              type: 'POST',
              url: 'registrar.aspx/RegistrarCuenta',
              data: '{' +
                  '"id":' + id +
                  ',"usuario":"' + user +
                  '","nombre":"' + nombre +
                  '","apellido":"' + apellido +
                  '","email":"' + email +
                  '","password":"' + password +
                  '","fechaNacimiento":"' + date +
                  '","tipo":' + 2 +
                  ',"op":' + 1 + '}',
              dataType: "json",               // Tipo de datos que se envian
              contentType: "application/json",            // Tipo de datos qu se envian
              timeout: 60000,             // Tiempo de espera para que occura un error de timeout
              error: function (xhr) {     // Evento que se dispara al ocurrir un error en la peticion
                  swal("Algo a salido mal...", "Error!", "error")
              },
              success: function (data) {   // Evento que se dispara cuando se realiza correctamente
                  swal(data.d, "", "success");
              }
          });
  </code></pre>
  
  <p>PD. registrar.aspx is located on my root folder, no inside a subfolder, etc. in the root.</p>
  
  <p>How can I solve my problem? Or what can I change to make it work.</p>