Hello all, I have tried many ways of executing this but its not happening .. here is the deal .. I have data displayed in table rows, every row has its id representing id of the person I wanna delete. I use jquery to collect this id from row where my button is located, here is the code how I do that, its working I'm just writing so you can get an insight of what I'm trying to accomplish :
var customer_id = $(this).parents("tr").attr('id');
When I test it using alert it works, here is the difficult part I'm simply stuck I have file called Delete.aspx here is its content
<%
string p = Request["value"]; int pInt = Int32.Parse(p);
var dataContext = new CustomersDataContext();
var customer = from m in dataContext.Customers
where m.id == pInt
select m;
dataContext.Customers.DeleteAllOnSubmit(customer);
dataContext.SubmitChanges();
%>
Now I'm trying to send the to the Delete.aspx values to delete person with particular id, and it works by typing Delete.aspx?value=7 in the browser, it deletes person with id 7. Now here is where I'm really really stuck. From Default.aspx i'm trying to reach Delete.aspx and pass the person id using jquery like this :
$(".btn-delete").click(function() {
var answer = confirm("If you press OK, this customer will be deleted?")
var customer_id = $(this).parents("tr").attr('id');
if (answer) {
$.ajax({
type: "POST",
url: "Delete.aspx",
data: "{value: '" + customer_id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
$(this).parents("tr").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow")
return false;
}
else {
alert("Customer has not been deleted!")
}
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
});
So now the result, When I click the button and confirm deletion I get "500 Internal server error", is this fixable or is there anymore other simple way of doing the same thing ?
Thank you
I've modified code .. but still I need some help .. I feel I'm so close so at least point me to right direction ..
here is my Delete.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Second_Question
{
public partial class Delete : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string p = Request["value"];
int pInt = Int32.Parse(p);
var dataContext = new CustomersDataContext();
var customer = from m in dataContext.Customers
where m.id == pInt
select m;
dataContext.Customers.DeleteAllOnSubmit(customer);
dataContext.SubmitChanges();
}
}
}
here is my Delete.aspx
<%
%>
any ideas ? thank you