[Solved] Uncaught ReferenceError: id is not defined in ASP.Net

lingers
 
on Aug 21, 2021 04:48 AM
1165 Views

i have 2 errors when trying to prevent pageload on button click

Material.aspx:30 Uncaught ReferenceError: id is not defined at Material.aspx:30

Material.aspx:686 Uncaught ReferenceError: ShowPopup is not defined

My complete code

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src=" https://code.jquery.com/jquery-3.5.1.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css" />
<script type="text/javascript" src="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="ASPSnippets_Pager.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        GetCustomers(1);
    });
    $(document).on("click", '.Pager .page', function () {
        GetCustomers(parseInt($(this).attr('page')));
    });
    $(document).on('click', '.view', function () {
        $('[id*=hfId]').val($(this).closest('tr').find('td').eq(0).html());
    });
    $.ajax({
        type: "POST",
        url: "Default.aspx/GetCustomersDetails",
        data: '{empId: ' + id + '}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var xmlDoc = $.parseXML(response.d);
            var xml = $(xmlDoc);
            var job_material = xml.find("job_material");
            var id = $(job_material[0]).find("id").text();
            var boardname = $(job_material[0]).find("boardname").text();
            var materialgsm = $(job_material[0]).find("materialgsm").text();
            var materialcode = $(job_material[0]).find("materialcode").text();
            var materialwebwidth = $(job_material[0]).find("materialwebwidth").text();
            var costpersqmeter = $(job_material[0]).find("costpersqmeter").text();
            $("#dialog").dialog({
                title: "VIEW  MATERIAL  DETAILS",
                width: 830,
                height: 300,
                buttons: {
                    Close: function () {
                        $(this).dialog('close');
                    }
                },
                modal: true
            });
            $("#dialog").parent().appendTo($("form:first"));
 
            $("#dialog1").dialog({
                title: "EDIT  MATERIAL  DETAILS",
                width: 830,
                height: 300,
                buttons: {
                    Close: function () {
                        $(this).dialog('close');
                    }
                },
                modal: true
            });
            $("#dialog1").parent().appendTo($("form:first"));
        }
    });
 
    var i = 0;
    function GetCustomers(pageIndex) {
        $.ajax({
            type: "POST",
            url: "Material.aspx/GetCustomers",
            data: '{pageIndex: ' + pageIndex + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                $('[id$=gvDetails]').prepend($("<thead></thead>").append($('[id$=gvDetails]').find("tr:first"))).DataTable().destroy();
                var xmlDoc = $.parseXML(response.d);
                var xml = $(xmlDoc);
                var customers = xml.find("job_material");
                var row = $("[id$=gvDetails] tbody tr:last-child").eq(0).clone(true);
                $("[id$=gvDetails] tbody tr").not($("[id$=gvDetails] tbody tr:first-child")).remove();
                $.each(customers, function () {
                    $("td", row).eq(0).html($(this).find("id").text());
                    $("td", row).eq(1).html($(this).find("boardname").text());
                    $("td", row).eq(2).html($(this).find("materialgsm").text());
                    $("td", row).eq(3).html($(this).find("materialcode").text());
                    $("td", row).eq(4).html($(this).find("materialwebwidth").text());
                    $("td", row).eq(5).html($(this).find("costpersqmeter").text());
 
                    $("[id$=gvDetails]").append(row);
                    row = $("[id$=gvDetails] tbody tr:last-child").eq(0).clone(true);
                });
                $("[id$=gvDetails] tbody tr:first-child").remove();
                if (i != 0) {
                    $('[id$=gvDetails]').DataTable({
                        "paging": false,
                        "info": false
                    });
                } else {
                    $('[id$=gvDetails]')
                        .prepend($("<thead></thead>").append($('[id$=gvDetails]').find("tr:first")))
                        .DataTable({
                            "paging": false,
                            "info": false
                        });
                }
                i++;
                var pager = xml.find("Pager");
                $(".Pager").ASPSnippets_Pager({
                    ActiveCssClass: "current",
                    PagerCssClass: "pager",
                    PageIndex: parseInt(pager.find("PageIndex").text()),
                    PageSize: parseInt(pager.find("PageSize").text()),
                    RecordCount: parseInt(pager.find("RecordCount").text())
                });
            },
            failure: function (response) {
                alert(response.responseText);
            },
            error: function (response) {
                alert(response.responseText);
            }
        });
    }
</script>

please help

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 27, 2021 06:26 AM

Use below code.

<script type="text/javascript">
    $(function () {
        GetCustomers(1);
    });
    $(document).on("click", '.Pager .page', function () {
        GetCustomers(parseInt($(this).attr('page')));
    });
    $(document).on('click', '.view', function () {
        var id = $(this).closest('tr').find('td').eq(0).html();
        $.ajax({
            type: "POST",
            url: "Material.aspx/GetCustomersDetails",
            data: '{empId: ' + id + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                var xmlDoc = $.parseXML(response.d);
                var xml = $(xmlDoc);
                var job_material = xml.find("job_material");
                var id = $(job_material[0]).find("id").text();
                var boardname = $(job_material[0]).find("boardname").text();
                var materialgsm = $(job_material[0]).find("materialgsm").text();
                var materialcode = $(job_material[0]).find("materialcode").text();
                var materialwebwidth = $(job_material[0]).find("materialwebwidth").text();
                var costpersqmeter = $(job_material[0]).find("costpersqmeter").text();
                ShowPopup();
            }
        });
    });

    var i = 0;
    function GetCustomers(pageIndex) {
        $.ajax({
            type: "POST",
            url: "Material.aspx/GetCustomers",
            data: '{pageIndex: ' + pageIndex + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                $('[id$=gvDetails]').prepend($("<thead></thead>").append($('[id$=gvDetails]').find("tr:first"))).DataTable().destroy();
                var xmlDoc = $.parseXML(response.d);
                var xml = $(xmlDoc);
                var customers = xml.find("job_material");
                var row = $("[id$=gvDetails] tbody tr:last-child").eq(0).clone(true);
                $("[id$=gvDetails] tbody tr").not($("[id$=gvDetails] tbody tr:first-child")).remove();
                $.each(customers, function () {
                    $("td", row).eq(0).html($(this).find("id").text());
                    $("td", row).eq(1).html($(this).find("boardname").text());
                    $("td", row).eq(2).html($(this).find("materialgsm").text());
                    $("td", row).eq(3).html($(this).find("materialcode").text());
                    $("td", row).eq(4).html($(this).find("materialwebwidth").text());
                    $("td", row).eq(5).html($(this).find("costpersqmeter").text());

                    $("[id$=gvDetails]").append(row);
                    row = $("[id$=gvDetails] tbody tr:last-child").eq(0).clone(true);
                });
                $("[id$=gvDetails] tbody tr:first-child").remove();
                if (i != 0) {
                    $('[id$=gvDetails]').DataTable({
                        "paging": false,
                        "info": false
                    });
                } else {
                    $('[id$=gvDetails]')
                        .prepend($("<thead></thead>").append($('[id$=gvDetails]').find("tr:first")))
                        .DataTable({
                            "paging": false,
                            "info": false
                        });
                }
                i++;
                var pager = xml.find("Pager");
                $(".Pager").ASPSnippets_Pager({
                    ActiveCssClass: "current",
                    PagerCssClass: "pager",
                    PageIndex: parseInt(pager.find("PageIndex").text()),
                    PageSize: parseInt(pager.find("PageSize").text()),
                    RecordCount: parseInt(pager.find("RecordCount").text())
                });
            },
            failure: function (response) {
                alert(response.responseText);
            },
            error: function (response) {
                alert(response.responseText);
            }
        });
    }

    function ShowPopup() {
        $('#label71').html('');
        $("#dialog").dialog({
            title: "VIEW  CYLINDER  DETAILS",
            width: 830,
            height: 500,
            buttons: {
                Close: function () {
                    $(this).dialog('close');
                }
            },
            modal: true
        });
        $("#dialog").parent().appendTo($("form:first"));
    };

    function ShowPopup1() {
        $('#label71').html('');
        $("#dialog1").dialog({
            title: "EDIT  CYLINDER  DETAILS",

            width: 830,
            height: 500,
            buttons: {
                Close: function () {
                    $(this).dialog('close');
                }
            },
            modal: true
        });

        $("#dialog1").parent().appendTo($("form:first"));
    };
</script>

 

dharmendr
 
on Aug 28, 2021 07:58 AM
dharmendr says:
    $(document).on('click', '.view', function () {
        var id = $(this).closest('tr').find('td').eq(0).html();
        $.ajax({
            type: "POST",
            url: "Material.aspx/GetCustomersDetails",
            data: '{empId: ' + id + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                var xmlDoc = $.parseXML(response.d);
                var xml = $(xmlDoc);
                var job_material = xml.find("job_material");
                var id = $(job_material[0]).find("id").text();
                var boardname = $(job_material[0]).find("boardname").text();
                var materialgsm = $(job_material[0]).find("materialgsm").text();
                var materialcode = $(job_material[0]).find("materialcode").text();
                var materialwebwidth = $(job_material[0]).find("materialwebwidth").text();
                var costpersqmeter = $(job_material[0]).find("costpersqmeter").text();
                ShowPopup();
            }
        });
    });

Set the hiddenfied from jquery.

$(document).on('click', '.view', function () {
    var id = $(this).closest('tr').find('td').eq(0).html();
    // Setting hidden field.
    $('[id*=hfId]').val(id);
    $.ajax({
        type: "POST",
        url: "Material.aspx/GetCustomersDetails",
        data: '{empId: ' + id + '}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var xmlDoc = $.parseXML(response.d);
            var xml = $(xmlDoc);
            var job_material = xml.find("job_material");
            var id = $(job_material[0]).find("id").text();
            var boardname = $(job_material[0]).find("boardname").text();
            var materialgsm = $(job_material[0]).find("materialgsm").text();
            var materialcode = $(job_material[0]).find("materialcode").text();
            var materialwebwidth = $(job_material[0]).find("materialwebwidth").text();
            var costpersqmeter = $(job_material[0]).find("costpersqmeter").text();
            ShowPopup();
        }
    });
});