更新产品数量而不进行回发

时间:2014-01-04 04:28:46

标签: javascript jquery asp.net function repeater

我正在做一个我陷入困境的项目。

当我添加到购物车时,我需要检查添加的数量以及产品,我正在使用JQuery函数来执行此操作。

虽然用户尚未签出,但我将qtyproduct_id存储在一个数据表中。如果用户删除了产品,我也会更改数量。

但是当我在购物车中添加产品时,回复不会发生。因此绑定到另一个数据表(使用数据库)的Qty不会更新其值。所以我很困惑该怎么办请帮我解决这个问题。

InsertProduct

function InsertProduct(product_id, qty, totalqty) {
    if (qty == "Details") {
        debugger;

        if ($('#txtqty').val().trim() != "") {
            if (!validateTextNumericInRange($('#txtqty').val())) {
                 alert("You have entered invalid product Quantity.");
                 return false;
            }
        }
    } else {
         qty = "1";
         price_type = 'sale';
    }

    debugger;

    var tempqty;
    if (qty == "Details") {
        tempqty = $('#lblcurrent_stock').text();
    } else {
        totalqty = parseInt(totalqty,10)

        if (totalqty != 0) {
            totalqty=totalqty-1;
            tempqty=totalqty; 
        } else {
            alert("Sorry We Are Running Of Stock For this Product. Will Soon Update the Stock");
            return false;
        }
    }

    $('#target').show();
    $('#target').html('<img src="images/ajax-loader1.gif" style="margin-left: 50%;padding: 10px;"/>')
    $.get("minicart.aspx?product_id="+product_id+"&qty="+qty+"&price="+pricetype_prescription+"&price_type="+price_type+"&tempqty="+tempqty+"#minicart", function( data ) {

        var resourceContent = data; 

        data = $(data).find('div#minicart');
        $('#target').html(data);

        var mini = $(resourceContent).find('div#pnlminicart')

        $('#smallcart').html(mini);
        $('#target').delay(7000).slideUp('slow');

        // can be a global variable too...
        // process the content...
    });
 return false;
}

此处detail适用于另一个正常运行的网页。这是我无法更新totalqty值。这里validateTextNumericInRange用于验证数量。

1 个答案:

答案 0 :(得分:1)

如果您在标签控件中显示信息,即使您在启动回发功能时使用jQuery更新数量,它也会从视图状态读取原始数量。我有同样的问题。我找到了一个解决方法: ASP.Net label value changed in JQuery but unchanged at postback

将数量存储在不可见的文本框中,并在回发时从中读取值。

相关问题