I have one LinkButton that I want to stop post-back on confirmation.
But the problem is even I click CANCEL on confirmation, it still post-backs.
How I bind it to confirmation func is like this:
LinkButton lbtn = e.Row.FindControl("btnDelete") as LinkButton;
lbtn.CommandArgument = e.Row.RowIndex.ToString();
const string js = @"confirmDelete(this,{0})";
lbtn.Attributes["onClick"] = string.Format(js, e.Row.RowIndex);
And this is the function:
function confirmDelete(lbtn, rowIndex) {
var tr = $(lbtn).closest('tr');
var formalColor= tr.css('background');
tr.css('background', '#FF0000');
var retVal = confirm("Are you sure you want to delete?");
tr.css('background', formalColor);
alert(retVal);
return retVal;
};
So what should I do to prevent post-back if the user clicks CANCEL -is it a special case for Linkbuttons?
Try to use
return confirmDelete(this,{0})