从GridView链接调用Jquery函数 [英] Calling Jquery function from GridView link
问题描述
我有一个带删除按钮的GridView。在ClientClick事件中,我调用了一个javascript函数,该函数用yes / no按钮打开jquery msgbox。如果用户点击是,我希望函数
ConfirmDeleteRecord()
返回true。 这是
< asp:TemplateField HeaderText =DeleteItemStyle-HorizontalAlign =Center >
< ItemTemplate>
< asp:LinkButton CommandArgument ='<%#DataBinder.Eval(Container.DataItem,ClientSkuID)%>'Text =Deleterunat =serverID =lnkDeleteOnClientClick = return ConfirmDeleteRecord()>< / asp:LinkButton>
< / ItemTemplate>
这是我的Javascript功能:
函数ConfirmDeleteRecord(){
var bResult = false;
$ .msgBox({
title:你确定?,
content:你确定要删除这个记录吗?,
type :确认,
按钮:[{value:Yes},{value:No},{value:Cancel}],
success:function(result){
if(result ==Yes){
bResult = true;
}
}
});
返回bResult;
}
问题在于代码永远不会去return bResult行。
谢谢大家。
这不起作用,因为$ .msgBox不是像confirm()那样的阻塞函数。合理?所有功能正在显示一些HTML。你需要做的是改变你的代码:
if(result ==Yes){
bResult = true;
}
类似于:
if(result ==Yes){
//在这里执行回发以删除记录。
}
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.
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.
}
这篇关于从GridView链接调用Jquery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!