删除记录时不应该 [英] deleting record when it shouldn't

查看:502
本文介绍了删除记录时不应该的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图展示一个确认框,它与确认完美配合,但不适用于我的自定义消息框,


$
$ b

 protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
{
if(e.RowType == DataControlRowType.DataRow)
{

LinkBut​​ton link =(LinkBut​​ton)e.Row.Cells [4] .Controls [2];
if(link!= null)
{
link.OnClientClick =return confirm('你确实要删除吗?');
}
}
}

  link.OnClientClick =ConfirmationBox(); 


函数ConfirmationBox()
{
$ .blockUI({message:$('#question'),css:{width:'275px'}
});
}

它显示消息框,但它也会删除我的记录:'' (



仍然感到困惑吗?检查一下,

显示讯息框的命令栏



编辑

 < script type =text / javascript> 
$(document).ready(function(){
$ b $('#yes')。click(function(){
$ .unblockUI();
return true;
});

$('#no')。click(function(){
$ .unblockUI();
return false;
});
}); $正如Jim所说的那样,b $ b< / script>


解决方案

你必须有

  link.OnClientClick =return ConfirmationBox(); 

ConfirmationBox应该总是返回false,您需要有一个更多按钮将执行删除操作,并且如果用户按下按钮,则需要触发该按钮的单击事件。我希望这是有道理的。

I am trying to show a confirmation box, which works perfectly with Confirm but doesn't work with my custom message box,

This works,

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {

        LinkButton link = (LinkButton)e.Row.Cells[4].Controls[2];
        if (link != null)
        {
            link.OnClientClick = "return confirm('Do you really want to delete?')";
        }
    }
}

BUT when i put this instead

link.OnClientClick = "ConfirmationBox()";


 function ConfirmationBox() 
    { 
    $.blockUI({ message: $('#question'), css: { width: '275px' } 
    }); 
    }

It shows message box but then it also deleting my record :'(

Still confused ? check this out,

Command field showing messagebox

Edit

<script type="text/javascript">
 $(document).ready(function() { 

 $('#yes').click(function() { 
        $.unblockUI(); 
        return true;
    });

    $('#no').click(function() { 
        $.unblockUI(); 
        return false; 
    }); 
}); 
 </script>

解决方案

As Jim said you have to have

link.OnClientClick = "return ConfirmationBox()";

ConfirmationBox should always return false. You need to have one more button which will perform the delete operation and you need to fire that button's click event if user press yes button. I hope that makes sense.

这篇关于删除记录时不应该的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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