Data not retaining in the text box coming from database on JQuery button click in asp.net Application
Most of the time what happen is we are able to write back end code to fetch data for text box to get auto filled on button click but it does not appear on front end or toggle for seconds in text box .
Solution to remove this problem is to give type to button as type="button" which is very necessary.
function getReportData() {
$.ajax({
"url": "ReportTable.aspx/GetReport",
"contentType": "application/json; charset=utf-8",
"type": "POST",
"dataType": "JSON",
"success": function (data) {
data = JSON.parse(data.d);
$.each(data, function (key, val) {
var tr = '<tr>';
tr += '<td>' + (key + 1) + '</td>';
tr += '<td>' + val.ReportId + '</td>';
tr += '<td>' + val.ReportName + '</td>';
tr += '<td>' + val.IsActive + '</td>';
tr += '<td>' + val.CreateUserId + '</td>';
tr += '<td>' + val.UpdateUserId + '</td>';
tr += '<td><button type = "button" id="btnEdit" value="Edit" class="edit" onclick="editClick(' + val.ReportId + ')">Edit</button>  <button type = "button" id="btnDelete" class="delete" value="Delete" data-key="' + (key + 1) + '" onclick="deleteClick(' + val.ReportId + ')">Delete</button> </td>';
tr += '</tr>';
$('tbody.exbody').append(tr);
});
$('#example').dataTable();
}
});
}
as button with no type attribute act as type="submit "and submit the data as soon it comes to the text boxes.
Solution to remove this problem is to give type to button as type="button" which is very necessary.
function getReportData() {
$.ajax({
"url": "ReportTable.aspx/GetReport",
"contentType": "application/json; charset=utf-8",
"type": "POST",
"dataType": "JSON",
"success": function (data) {
data = JSON.parse(data.d);
$.each(data, function (key, val) {
var tr = '<tr>';
tr += '<td>' + (key + 1) + '</td>';
tr += '<td>' + val.ReportId + '</td>';
tr += '<td>' + val.ReportName + '</td>';
tr += '<td>' + val.IsActive + '</td>';
tr += '<td>' + val.CreateUserId + '</td>';
tr += '<td>' + val.UpdateUserId + '</td>';
tr += '<td><button type = "button" id="btnEdit" value="Edit" class="edit" onclick="editClick(' + val.ReportId + ')">Edit</button>  <button type = "button" id="btnDelete" class="delete" value="Delete" data-key="' + (key + 1) + '" onclick="deleteClick(' + val.ReportId + ')">Delete</button> </td>';
tr += '</tr>';
$('tbody.exbody').append(tr);
});
$('#example').dataTable();
}
});
}
as button with no type attribute act as type="submit "and submit the data as soon it comes to the text boxes.
Comments
Post a Comment