Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

XML
[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!
Posted

1 solution

And I fill the table for the first time on de Load method with:

VB
foreach (DatosUbicacion datosFront in origenes)
                    {
                        html += "<tr>" +
                                    "<td>" + datosFront.TipoParcela + "</td>" +
                                    "<td>" + datosFront.CuentaDescriptor + "</td>" +
                                    "<td>" + datosFront.ParcelaDescriptor + "</td>" +
                                    "<td>" + datosFront.EstadoParcela + "</td>" +
                                    "<td>" + datosFront.Departamento + "</td>" +
                                    "<td>" + datosFront.Pedania + "</td>";



                        html += "</tr>";
                    }

                    lblCuentas.Text = html;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900