Here is the thing, I have the following jQuery ajax call, where I add a to a table:
$.ajax({
type: "POST",
url: "datosParcelas.aspx/AgregarOrigen",
data: "{'cuenta' : '" + nroCta + "'}",
contentType: "application/json; utf-8",
dataType: "json",
success: function (response) {
if (response.d)
if ($('#tblCuentas > tbody > tr').length == 1)
$("#tblCuentas").css('display', '');
$("#tblCuentas > tbody > tr:last").after(response.d);
$('#cp_lblError').html('');
$("#txtCuenta").val('');
$("#txtCuenta").focus();
}
else {
$('#cp_lblError').html('');
}
$(".loading").hide();
$btn.button('reset');
},
error: function (error) {
showAlertModal("Error",error);
$(".loading").hide();
$btn.button('reset');
}
});
I return the with the webMethod:
[WebMethod(EnableSession = true)]
public static string AgregarOrigen(string cuenta)
{
string html = null;
try
{
//cuenta = cuenta.Trim().Replace("-", "").Replace("/","");
if (HttpContext.Current.Session["idTramite"] == null)
return "ERROR:SESION";
if (string.IsNullOrEmpty(cuenta))
return "ERROR:Ingrese la cuenta";
using (TDService ws = new TDService())
{
DatosUbicacion[] datosFront = ws.TramiteLoadDatosUbicacion(0, 0, cuenta);
if (datosFront != null && datosFront.Length > 0)
{
if (ws.TD_Cuenta_Save((int)HttpContext.Current.Session["idTramite"], datosFront[0].IdCuenta))
{
cuentas.Add(datosFront[0].IdCuenta);
html = "<tr>" +
"<td>" + datosFront[0].TipoParcela + "</td>" +
"<td>" + datosFront[0].CuentaDescriptor + "</td>" +
"<td>" + datosFront[0].ParcelaDescriptor + "</td>" +
"<td>" + datosFront[0].EstadoParcela + "</td>" +
"<td>" + datosFront[0].Departamento + "</td>" +
"<td>" + datosFront[0].Pedania + "</td>" +
"<td><a class='elimina' title='Eliminar' onclick='fn_eliminarCuentaClick(this)'><img src='images/delete.png' /></a> <p class='hidden'>" + datosFront[0].IdCuenta + "<p></td>" +
"</tr>";
HttpContext.Current.Session["origenes"] = cuentas;
}
else
return "ERROR: No se pudo insertar el Titular. Intente mas tarde.";
}
else
return "ERROR:La Cuenta ingresada no existe";
}
}
catch (Exception ex)
{
LogError.Write(ex);
return "ERROR: Error inesperado. No se pudo asociar la Cuenta al tramite " + (int)HttpContext.Current.Session["idTramite"] + ". Intente mas tarde.";
}
return html;
}
The problem I have, is that when I do a postback on the page, the rows added through ajax, deletes from de table. What am I doing wrong?? I will appreciate any help!