确认删除的记录,从方法 [英] Confirm delete of record, from method

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

问题描述

我如何能弹出一个消息框,确认删除,从方法里?

How can I pop up a message box to confirm a delete, from inside a method?

通常我只会用下面这行我的按钮: 的OnClientClick =返回确认('你确定要删除此评论吗?');

Normally i would just use the following line in my button: OnClientClick="return confirm('Are you sure you want to delete this comment?');"

然而,这种删除方法也可以通过查询字符串叫,所以我需要在方法的确认消息框的功能吗?

However this delete method can also be called by a querystring, so I need the confirm message box functionality in the method, please?

// delete comment method
private void DeleteComment()
{

            int commentid = Int32.Parse(Request.QueryString["c"]);

            // call our delete method
            DB.DeleteComment(commentid);

}

我无法通过点击code中的按钮,因为它不火的的OnClientClick事件 btnDelete_Click(NULL,NULL);

I can't click the button through code, because it doesn't fire the OnClientClick event btnDelete_Click(null, null);

问候

推荐答案

我会建议做这样的事情。

I would recommend doing something like this.

添加第二个查询字符串参数如果确认或不规定。无疑增加了一些code,以确认用户已登录,这样这个查询字符串的方法没有得到一个WebCrawler的或有什么东西砸,不小心删除您的所有意见。

Add a 2nd query string argument to dictate if it is confirmed or not. Definitely add some code to confirm that the user is logged in so that this query string methodology doesn't get hit by a webcrawler or something and accidentally delete all your comments.

// delete comment method
private void DeleteComment()
{

    if(Boolean.Parse(Request.QueryString["confirm"])
    {
          int commentid = Int32.Parse(Request.QueryString["c"]);

          // call our delete method
          DB.DeleteComment(commentid);
    }
    else
    {
          ScriptManager.RegisterStartupScript(this, this.GetType(), "ConfirmDelete", @"
            if(confirm('Are you sure you want to delete this comment?'))
                window.location = '[insert delete location with confirm set to true]';                
          ", true);
    }

}

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

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