在asp.net中执行删除之前,请先确认Linkbutton. [英] Confirm for Linkbutton before performing delete in asp.net

查看:37
本文介绍了在asp.net中执行删除之前,请先确认Linkbutton.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的asp.net表单中有一个删除Linkbutton.当用户单击按钮时,它将从我的数据库中删除内容,该内容已在按钮的OnClick()中进行了编码.但是在此之前,我需要有一个确认框,其中包含是或否选项.如果用户单击是",如何删除?如果用户单击否",如何限制删除?我的问题是onclick和onclientclick不能一起使用.请帮助我..这是示例代码..

I have a delete Linkbutton in my asp.net form. When the user clicks the button it will delete the contents from my db, which has been coded in the OnClick() of the button. But before that I need to have a confirm box which has yes or no options. How do I go about the deletion if the user clicks on "yes" and restrict deletion if user clicks on "no"? My problem is that onclick and onclientclick do not work together. Please help me ..Here is the sample code..

我将以下脚本放在哪里?

Where do I place the following script?

<script type="text/javascript">
    function Confirm() {
        var confirm_value = document.createElement("INPUT");
        confirm_value.type = "hidden";
        confirm_value.name = "confirm_value";
        if (confirm("Do you want to delete data?")) {
            confirm_value.value = "Yes";
        } else {
            confirm_value.value = "No";
        }
        document.forms[0].appendChild(confirm_value);
    }
</script>

后面的代码:

protected void Mark_Click(object sender, EventArgs e)
{
    a.Delete(name);
}

推荐答案

使用以下代码:

OnclientClick="return Confirm()"

Confirm()函数返回true/false,如果Confirm()返回true,则将发生回发.否则

Return true/false from Confirm() function, if Confirm() return true then postback will happen otherwise not.

请参考在线示例进行测试

注意:我们使用了大写的Confirm()方法,因为post具有用户定义的功能Confirm().所以请不要与Java脚本的内置功能Confirm()混淆.

Note: We have used Confirm() in upper case because post has user defined function Confirm(). so please don't confuse with inbuilt function confirm() of java script.

这篇关于在asp.net中执行删除之前,请先确认Linkbutton.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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