I created a table from my database and now I want to add rows and save it. My problem is when I add a row for a second time, I do saved the row before in my database, but this row gets as soon as the second blank row appears. If a refresh the page or using location.reload() first row is visible but not the second blank one.
I wrote in javascript (but my whole program runs in c#) :
function addRow() {
var i = parseInt(document.getElementById('counter').value);
if ((i-1)>=0) {
var id = guid();
save_row_before(i-1);
var row = '<input ID="id'+ i + '" runat="server"type="text"
document.getElementById('table').getElementsByTagName('tbody')[0].innerHTML += row;
document.getElementById('counter').value = i + 1;
}
}
function save_row_before(i) {
var r = document.getElementById('id' + i).value ;
$.ajax({
type: "POST",
url: "Default.aspx/saveRows",
data: '{row: "' + r + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false
});
}
Thanks in advance!!