I have a list of elements in a gridview and I need to delete them with web-method, update gridview and don't reload the whole page. But after every call the page reloads.
My button:
<asp:Button ID="btnDelete" runat="server" CssClass="btn btn-default" Text="Delete a row" OnClientClick="DeleteRecord() return false;" />
JS-script for it:
function DeleteRecord() {
var inputData = jsTextBox();
if (confirm('Are you certain you want to delete this record?')) {
$.ajax({
type: "POST",
url: "SubjectTable.aspx/DeleteRecord",
data: inputData,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$('#<%=gdViewSubj.ClientID%>').empty();
if (data.d.length > 0) {
fillGrid(data);
}
},
failure: function (data) {
alert(data.d);
}
});
}
return false;
}
function fillGrid(data) {
$('#<%=gdViewSubj.ClientID%>').append("<tr><th>SUBJ_ID</th><th>SUBJ_NAME</th><th>HOUR</th><th>SEMESTER</th></tr>");
for (var i = 0; i < data.d.length; i++) {
$('#<%=gdViewSubj.ClientID%>').append("<tr><td>" +
data.d[i].SUBJ_ID + "</td> <td>" +
data.d[i].SUBJ_NAME + "</td> <td>" +
data.d[i].HOUR + "</td> <td>" +
data.d[i].SEMESTER + "</td></tr>");
}
}
So when I check the script step by step, I see that everything's fine, gridview is cleared and then filled without deleted row. But after end of the script page reloads and I see the old row. If I close page and open it again, then I get an updated table.
What is the root of this issue and how to fix it?