This is a migrated thread and some comments may be shown as answers.

Save row only works with alert or breakpoint (Ajax)

1 Answer 23 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Ron asked on 22 Jan 2014, 09:43 PM

I'm using a rad grid to display invoice items. The first column of the grid is a drop down menu which gives the option to select an item. Once the item is selected the remaining columns will auto populate with price , quantity, amount, etc. Once the amount column populates . I execute a function (OnValueChanged event) to save that row of data with ajax web method. The problem occurs after the first row of data saves. If you immediately move to the second row and select an item sometimes it saves and sometimes it doesn't. If I wait about a minute to select an item in another row it will work but that's not ideal. It always works if I place a breakpoint or an alert in the function. I think it maybe an ajax issue BTW it works perfectly in IE.  Would appreciate any help. I've attached a screen shot of the grid and the code.

function AmountChanged(sender, args) {
          if (args._oldValue != '') {
          console.log("Row Number " + rowIndex1)
function SaveInvoiceItems() {

                var masterTable = $find("<%=grdInvoiceItems.ClientID%>").get_masterTableView();
                //for (var row = 0; row < masterTable.get_dataItems().length; row++) {
                var Id = masterTable.getCellByColumnUniqueName(masterTable.get_dataItems()[rowIndex1], "Id");

                var grid = $find("<%=grdInvoiceItems.ClientID%>");
                var masterTbl = grid.get_masterTableView();
                var gridRow = masterTbl.get_dataItems()[rowIndex1];

                var item = gridRow.findControl("ddlItems")._text;
                var description = gridRow.findControl("txtDescription")._text;
                var price = gridRow.findControl("txtPrice")._text;
                var qty = gridRow.findControl("txtQty")._text;
                var discount = gridRow.findControl("txtDiscount")._text;
                var amount = gridRow.findControl("lblAmount")._text;

                if (discount == '')
                    discount = 0;
                if (price == '')
                    price = 0;
                if (qty == '')
                    qty = 0;
                if (amount == '')
                    amount = 0;

                var obj_as_object = { id: Id.innerHTML, item: item, description: description, price: price, qty: qty, discount: discount, amount: amount };;
                var obj_as_string = JSON.stringify(obj_as_object);

                var xhr = $.ajax({
                    type: "POST",
                    url: "/WebService/InvoiceWebService.asmx/UpdateRecurringInvoiceItems",
                    data: obj_as_string,
                    'async': false,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    beforeSend: function (xhr, settings) {
                        xhr.startTime = new Date().getTime();
                        $("#wait").css("display", "block");
                    complete: function (xhr) {
                        var elapsed = new Date().getTime() - xhr.startTime;
                        if (elapsed < 3000) {
                            $("#wait").css("display", "block").delay(7000 - elapsed).hide(1);
                        } else {
                            $("#wait").css("display", "block").hide();

                //)).then(function (data, textStatus, jqXHR) {
                //    //alert("what is this"); // Alerts 200

                //setTimeout(doSomething(Id.innerHTML), 3000);



1 Answer, 1 is accepted

Sort by
Viktor Tachev
Telerik team
answered on 27 Jan 2014, 11:53 AM
Hi Ron,

In order to prevent this behavior you could try calling the update command with a timeout and see if it makes a difference. Additionally you could try updating the grid without Ajax and check if the functionality works correctly.

There could also be errors on the page. Check the console for the browser where the issue is observed for JavaScript errors.

Viktor Tachev
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Asked by
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question