title: call a asp.net vb function from jquery
body: <p>I have the following error when trying to call a function in vb code from javascript (jquery)</p>
  
  <p>In the view (.aspx) I have the following code:</p>
  
  <pre><code>&lt;asp:ImageButton ID="imgbtnRetirar" runat="server" OnClientClick="return alerteliminar();" IdEliminar='&lt;%# Eval("CODIGO") %&gt;'
                                                              ImageUrl="~/Images/ic_eliminar.gif" ToolTip="Borrar al Usuario Aprobador"&gt;&lt;/asp:ImageButton&gt;
  </code></pre>
  
  <p>In the script I have the following code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function alerteliminar() {
          var letra="cancel";
          $("#texto").text("Seguro que desea Eliminar al usuario autorizador?");
          $( "#dialog-message" ).dialog({
            modal: true,
            buttons: {
              "Ok": function() {
                $( this ).dialog( "close" );
                 var id = $("#ctl00_ctphFrmContent_grvLista_ctl02_imgbtnRetirar").attr("ideliminar");
                  $.ajax(
                  {
                      type: "POST",
                      url: "AprobadoresxModificacion.aspx/EliminarRegistro",
                      data: "{'Id':'" + id + "'}",
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      success: function (msg) {
                          console.log(msg)
                      }
                  });
              },
              "Cancel": function() {
              $( this ).dialog("Eliminar");
              }
            }
          });
        }
      &lt;/script&gt;
  </code></pre>
  
  <p>And in the vb code, I have the following:</p>
  
  <pre><code>&lt;System.Web.Services.WebMethod()&gt; _
      Public Function EliminarRegistro(ByVal Id As Integer) As String
          Try
              If Me.BorrarAprobador(Integer.Parse(Id)) Then
                  Me.btnBuscar_Click(Nothing, Nothing)
                  Return "OK"
              Else
                  Me.Mensaje("No se pudo borrar el registro")
                  Return "BAD"
              End If
          Catch ex As Exception
              Return ex.Message
          End Try
      End Function
  </code></pre>
  
  <p>The error I get is the following:
  <a href="http://localhost:2091/WebSMEX/Paginas/Mantenimiento/AprobadoresxModificacion.aspx/EliminarRegistro" rel="nofollow">http://localhost:2091/WebSMEX/Paginas/Mantenimiento/AprobadoresxModificacion.aspx/EliminarRegistro</a> 500 (Internal Server Error)</p>