I'm trying to pass a single parameter to my code behind. I'm reaching the success end of ajax but the method in my aspx.cs code behind doesn't get called. I'm using a masterfile if it makes a difference.
Javascript:
$(document).ready(function () {
var someID = "";
$('.glyphicon-trash').click(function () {
$.ajax({
type: "POST",
url: "fileName.aspx/deleteSomething",
data: "{'deleteSomeID':'" + someID + "'}", // someID is assigned to a value by another button
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert("success"); // this alert works.
}
});
});
});
fileName.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
//... stuff here
}
[WebMethod]
public static void deleteSomething(string deleteSomeID)
{
MySqlDbUtilities db = new MySqlDbUtilities();
MySqlCommand cmd;
string sql = "DELETE FROM Targets WHERE targetID = @someID";
cmd = db.GetCommand(sql);
cmd.Parameters.AddWithValue("@someID", deleteSomeID);
cmd.ExecuteNonQuery();
db.Dispose();
}
The "someID" is filled when you click a button on the page. That is working properly, I triple checked. The method however doesn't do anything. I don't know if it's being reached either. Any ideas?