问题
After hours of trying every possible way, I give up. Maybe you guys can see what i'm doing wrong here.
I have a GridView with a Delete button. On the ClientClick event i call a javascript function that opens a jquery msgbox with yes/no buttons. If the user clicked yes, I would like the function ConfirmDeleteRecord() to return true.
This is how the "Delete" column on the GridView looks like:
<asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ClientSkuID") %>' Text="Delete" runat="server" ID="lnkDelete" OnClientClick="return ConfirmDeleteRecord()"></asp:LinkButton>
</ItemTemplate>
This is my Javascript function:
function ConfirmDeleteRecord() {
var bResult = false;
$.msgBox({
title: "Are You Sure?",
content: "Are you sure you want to delete this record?",
type: "confirm",
buttons: [{ value: "Yes" }, { value: "No" }, { value: "Cancel"}],
success: function (result) {
if (result == "Yes") {
bResult = true;
}
}
});
return bResult;
}
The problem is that the code never get to to "return bResult" line.
Thank you all.
回答1:
That won't work because $.msgBox is not a blocking function like confirm() is. Make sense? All that function is doing is showing some HTML. What you need to do is instead change your code from this:
if (result == "Yes") {
bResult = true;
}
To something like:
if (result == "Yes") {
//perform postback here to delete the record.
}
来源:https://stackoverflow.com/questions/13782051/calling-jquery-function-from-gridview-link