从GridView链接调用Jquery函数 [英] Calling Jquery function from GridView link

查看:95
本文介绍了从GridView链接调用Jquery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过几个小时的尝试,我放弃了。也许你们可以看到我在这里做错了什么。
我有一个带删除按钮的GridView。在ClientClick事件中,我调用了一个javascript函数,该函数用yes / no按钮打开jquery msgbox。如果用户点击是,我希望函数 ConfirmDeleteRecord()返回true。



这是

 < asp:TemplateField HeaderText =DeleteItemStyle-Horizo​​ntalAlign =Center > 
< ItemTemplate>
< asp:LinkBut​​ton CommandArgument ='<%#DataBinder.Eval(Container.DataItem,ClientSkuID)%>'Text =Deleterunat =serverID =lnkDeleteOnClientClick = return ConfirmDeleteRecord()>< / asp:LinkBut​​ton>
< / 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;

}



问题在于代码永远不会去re​​turn bResult行。

谢谢大家。

解决方案 div>

这不起作用,因为$ .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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆