Why do I get error table id = MainContent_table - Ajax. When trying to do lazy loading?

0

What I want to do is a datatable with a weak load, that will load the data according to what is being asked.

Code of c #:

public partial class ConsultarEvidencia : System.Web.UI.Page
    {
        private int conta = 0;
        public string Inicio="";
        public string Fin = "";

        protected void Page_Load(object sender, EventArgs e)
        {


        }
        public void btnOk_T_Onclick(object sender, EventArgs e)
        {
            DataTable data = new DataTable();
            HistoryBI historyBi=new HistoryBI();

            Inicio = dtInicio.Text;
            Fin = dtFin.Text;

            data = historyBi.ConsultarEvidencia(Inicio,Fin);


            //DirectoryInfo d = new DirectoryInfo(@"C:\Users\Ned-Design\Documents\projects\NederaV4\Administrators\Temp");//Assuming Test is your Folder
            //FileInfo[] Files = d.GetFiles("*.png"); //Getting Text files

            System.Web.UI.HtmlControls.HtmlGenericControl createI = new System.Web.UI.HtmlControls.HtmlGenericControl("i");
            createI.ID = "createI";
            string str ="";



            foreach (DataRow dtRow in data.Rows)
            {

                TableRow row = new TableRow();

                for (int i=0;i<dtRow.ItemArray.Length;i++)
                {
                    TableCell cell1 = new TableCell();
                        cell1.Text = dtRow[i].ToString();

                   row.Cells.Add(cell1);

                }

                tabla.Rows.Add(row);

            }



        }


    }

Datatble code in jquery:

$(document).ready(function () {


            $("[id$='dtInicio'],[id$='dtFin']").datepicker($.datepicker.regional["<%= Session["Lang"] %>"]);


            $('#MainContent_tabla').DataTable({
                dom: 'Blfrtip',
                buttons: [
                    'excelHtml5',
                    'pdfHtml5'
                ],
                columns: [
                    { title: "Id del Usuario" },
                    { title: "Nombre" },
                    { title: "Lectura de QR" },
                    { title: "Toma de evidencia" },
                    { title: "Diferencia" },
                    {title: "Placas"},
                    { title: "Imagen", "mRender": function (data, type, full) {
                        return '<center><a class="fa fa-picture-o" aria-hidden="true" style="font-size:24px;cursor:pointer;" href=/Temp/'+full[6]+'></a></center>';
                    }
                    }
                ],
                "language": {
                    "lengthMenu": "Mostrar _MENU_ Registros por pagina",
                    "zeroRecords": "No hay ningun registro que coincida",
                    "info": "Mostrando pagina _PAGE_ of _PAGES_",
                    "infoEmpty": "No hay registros disponibles",
                    "infoFiltered": "(filtered from _MAX_ total records)",
                    "search": "Buscar Palabra:",
                    "paginate": {
                        "previous": "Siguiente",
                        "next": "Anterior"
                    }
                },
                "processing": true,
                "serverSide": true,
                "ajax": "ConsultarEvidencia.aspx.cs",
                "deferLoading": 57

            });
        });

The console error is:

The datatable does not work, what am I doing wrong?

    
asked by David 22.05.2018 в 23:24
source

1 answer

0

Error 404 means that the requested resource was not found.

You have an error assigning the property "ajax": "ConsultarEvidencia.aspx.cs" since with ASP.NET you should not call the name of the file where the source code is located as it is done with PHP, but you should create a method within your class that return the necessary information to fill the DataTable and this method is the one you should call.

CODEBEHIND

[System.Web.Services.WebMethod]
public static string GetData()
{
    return "Hello World!!";
}

JAVASCRIPT

To assign it to the DataTable, it would be:

"ajax": "ConsultarEvidencia.aspx/GetData"
    
answered by 22.05.2018 в 23:42