I have a LinkButton which only needs to postback when the Ajax-Call inside the delete function fails.
The ajax-call calls a Webmethod which throws an exception if the deletion of the rows failed for some reason.
When i throw the exception the ajax call reaches the “error”-branch (as expected). But when the “deleteSelectedRows” function returns false, the postback is not being stopped.
How can i archieve this?
<asp:LinkButton ID="Delete" ClientIDMode="Static" runat="server" Text="Delete" OnClientClick="return deleteSelectedRows()" ></asp:LinkButton>
//the jquery code
function deleteSelectedRows() {
//get selected rows
var selectedRows = ... getting ids ...
var postData = "{ 'IDs':'" + selectedRows + "'}";
var url = "WebMethods.aspx/DeleteRows";
var status= jQuery.ajax({
url: url,
dataType: "html",
async: false,
type: "POST",
data: postData,
contentType: "application/json; charset=utf-8",
success: function (msg) {
return true;//continue postback
},
error: function (err) {
jQuery.jGrowl('Fehler: Auftragspositionen konnten nicht gelöscht werden! Möglicherweise existieren bereits Transaktionen zu dieser Auftragsposition.');
//e.preventDefault();
return false;//stop postback
}
});
return status.status == 200;//true when delete worked, false otherwise
}
EDIT: This works when i use a asp:Button instead of asp:Linkbutton… but i dont have a clue why?!
ok, i solved it:
the problem was due to the following code which i used to stop execution of links if they are disabled (maybe this is useful for someone else too, so i post it here):
i changed this to, and now its working:
i have to admit, that the question couldnt be solved with the information i provided!