I am encountering an issue with deleting items from a list, as my delete function in the .aspx.cs file is not being called.
Below is my JavaScript code:
function doTheDelete(doIDeleteExpenses) {
if (selectedExpensesList.length > 0) {
$.ajax({
type: "POST",
url: '<%=ResolveUrl("~/Expenses/ViewExpenses.aspx/deleteSelectedExpense")%>',
data: "{'DeleteExpenses' : " + "'" + doIDeleteExpenses + " '}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var ss = data.d;
if (ss.length > 0) {
for (var i = 0; i < ss.length; ++i) {
$.noty.consumeAlert({ layout: 'center', type: 'error', dismissQueue: true });
alert(ss[i]);
}
}
$("#viewTasksGrid").flexReload();
},
error: function (data) {
$.noty.consumeAlert({ layout: 'center', type: 'error', dismissQueue: true, modal: true });
alert('Error Deleting Expense');
if (window.console) {
console.log(data);
}
}
});
} else {
showMessage('No expenses are selected.');
}
}
function getSelectedExpenseIDs() {
var selectedExpensesList = new Array;
var i = 0;
$('.expenseCheckBox:checked').each(function () {
if ($(this)[0].id !== "checkAllExpenses") {
selectedExpensesList[i] = $(this)[0].id.split('_')[1];
++i;
}
});
return selectedExpensesList;
}
Here is the method in the aspx.cs file that is not getting called:
[WebMethod]
public static string[] deleteSelectedExpense(bool DeleteExpenses, String[] ExpID)
{
var rList = new List<string>();
var canDeleteExpenses = false;
var investigatorID = (int)HttpContext.Current.Session["InvestigatorID"];
var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString());
var cmd = new SqlCommand("p_Admin_Permissions_CanDeleteExpenses", conn);
// Code for handling database connection and deletion of expenses
return rList.ToArray();
}
When inspecting the browser console, I receive an internal server error (500).