Editor in WebForm .Net and C# postback doesnt get new values

Editor in WebForm .Net and C# postback doesnt get new values

JuJoGuAlJuJoGuAl Posts: 32Questions: 2Answers: 0

I have the code of GridView and it turn to datatable with editor, when i click in one row (inline editor) i change the values of any cell after i use a button to do the (Submit) the Server (C#) dont get the edited values, it returns the original values, how i can solve it? im using Web Form with C# and .Net

Code: https://jsfiddle.net/JuJoGuAl/m5sqebvd/

How i can solve it?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,133Questions: 1Answers: 10,399 Site admin

    Can you show me the Javascript you are using please?

    Thanks,
    Allan

  • JuJoGuAlJuJoGuAl Posts: 32Questions: 2Answers: 0
    edited February 2020

    @allan this is:

        var _tabla = "gridTest";
        var editor; //editor var
        var campos = [], campos2 = [];
        
        //reading the table header
        jQuery('#'+_tabla +' thead tr:last th').each(function(i){
            var atrib = jQuery(this).attr("abbr")===undefined ? "none_"+i: jQuery(this).attr("abbr");
            campos[i]={name:atrib};
            if(atrib==="correlativo"){
                campos2[i] = {data: atrib, render: $.fn.dataTable.render.number('.',',', 2)};
            }else{
                campos2[i]={data:atrib};
            }
        });
        
        editor = new $.fn.dataTable.Editor({
            //ajax: "../php/staff.php",
            table: "#"+_tabla,
            idSrc:  'correlativo', //key
            fields: campos
        });
        
        jQuery('#'+_tabla).on('dblclick','tbody td', function (e) {
            editor.inline( this, { submit: 'allIfChanged'});
        });
        
        var options = {
            destroy: true,
            dom: 'Bfrtip',
            buttons: {
                dom: {
                    button: {
                        className: 'btn btn-outline-info mr-2'
                    }
                },
                buttons: [
                    {
                        //EXCEL
                        extend: 'excelHtml5',
                        text: '<i class="fas fa-file-excel"></i> EXCEL',
                        titleAttr: 'EXPORTAR A EXCEL',
                        footer: true,
                        exportOptions: {
                            columns: ':not(.noexportar)',
                        },
                    },
                    {
                        //PDF
                        extend: 'pdfHtml5',
                        text: '<i class="fas fa-file-pdf"></i> PDF',
                        titleAttr: 'EXPORTAR A PDF',
                        orientation: "landscape",
                        footer: true,
                        pageSize: "A4",
                        exportOptions: {
                            columns: ':not(.noexportar)',
                            format: {
                                body: function (data, row, column, node) {
                                    var newdata = (jQuery(node).text()).trim();
                                    return newdata;
                                },
                            }
                        },
                    },
                    {
                        //PRINT
                        extend: 'print',
                        text: '<i class="fas fa-print"></i> IMPRIMIR',
                        titleAttr: 'IMPRIMIR',
                        footer: true,
                        exportOptions: {
                            columns: ':not(.noexportar)',
                            format: {
                                body: function (data, row, column, node) {
                                    var newdata = (jQuery(node).find(".basico").length > 0) ? formatNumber(jQuery(node).find(".basico").text()) : jQuery(node).text().trim()
                                    return newdata;
                                },
                            }
                        },
                    }
                ]
            },
            scrollX: true,
            scrollY: '70vh',
            scrollCollapse: true,
            columns: campos2,
        };
        
        jQuery('#' + _tabla).DataTable(options);
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,133Questions: 1Answers: 10,399 Site admin

    You've got this commented out:

    //ajax: "../php/staff.php",
    

    so nothing is being submitted anywhere - it is just being saved locally in the DataTable.

    If you want to use Editor with .NET have a look at the documentation here to see how to use our server-side libraries to write the data to the database.

    Also there is an Editor download package for .NET which you can download and install to get the examples working on your computer / server which can be useful for experimenting with the options and seeing how it all fits together.

    Allan

  • JuJoGuAlJuJoGuAl Posts: 32Questions: 2Answers: 0

    But that examples apply to MCV .net and im using WebForm (Client-Server), and i cant do the "updates" via ajax (there a lot code for do it), i need do the update via Server (Postback)

  • allanallan Posts: 63,133Questions: 1Answers: 10,399 Site admin
    Answer ✓

    Hi,

    You are absolutely right, our examples focus on WebAPI it fits really well with Ajax requests such as those Editor uses.

    That said, as pour WebForms documentation shows](https://editor.datatables.net/manual/net/webform) it is possible to use Editor in a WebForm / ASPX environment.

    If you want to do the update to the server using a <form> element submit rather than Ajax, then Editor is not the right tool to use.

    Allan

This discussion has been closed.