需要javascript代码来确认删除按钮删除 [英] need javascript code to confirm deletion by buttonfield delete

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

问题描述

你好

我是新来的,这是我的第一个问题。我有一个带按钮字段删除的gridview。它工作正常。我想使用javascript代码添加一个确认框。我不能使用onclientclick因为我不使用templatefield.please帮助。

解决方案

hi,

在这种情况下你需要在gridview / listview ItemDataBound事件上注册确认脚本。

参考这些链接将解决你的问题。

ASP.NET GridView删除确认使用asp:CommandField [ ^ ]

http://highoncoding.com/Articles/138_GridView_Confirm_When_Delete.aspx [ ^ ]


< blockquote>这是最简单的方法: http://www.w3schools.com/jsref/met_win_confirm.asp [ ^ ]。



或者,您可以使用jQuery创建精彩且非常灵活的确认对话框。看看:

http://myclabs.github.io/jquery.confirm/ [ ^ ]。



如果您需要学习jQuery(强烈推荐),请参阅:

http ://en.wikipedia.org/wiki/JQuery [ ^ ],

http://jquery.com/ [ ^ ],

http ://learn.jquery.com/ [ ^ ],

http://learn.jquery.com/using-jquery-core/ [ ^ ],

http://learn.jquery.com/about-jquery/how-jquery-works/ [<一个href =http://learn.jquery.com/about-jquery/how-jquery-works/target =_ blanktitle =New Window> ^ ](从这里开始)。



关于onclienclick的问题看起来与我无关,我甚至无法理解你的想法。无论如何,您需要在客户端获得确认。您不必使用后面的ASP.NET代码来添加事件处理程序,生成一些HTML,它可以包含任何JavaScript。







回应OP对此答案的评论:



答案在此评论中。请注意,他的活动可以取消:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewdeleteeventargs.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel.aspx [ ^ ]。



-SA


< asp: imagebutton id =ImageButton1runat =server> 
ImageUrl =〜/ images / grdbtndelete.pngCommandName =Delete
OnClientClick =return confirm(您确定要删除此条目吗?); />
< / asp:imagebutton>


hello
im new here and this is my first question.i have a gridview with button field delete. it works fine.i want to add a confirmation box using javascript code.i cannot use onclientclick because im not using templatefield.please help.

解决方案

hi,
in such cases you need to register the confirmation script on gridview/listview ItemDataBound Event.
Refer to these links will solve your problem.
ASP.NET GridView delete confirmation using asp:CommandField[^]
http://highoncoding.com/Articles/138_GridView_Confirm_When_Delete.aspx[^]


This is the simplest possible way: http://www.w3schools.com/jsref/met_win_confirm.asp[^].

Alternatively, you can create wonderful and very flexible confirmation dialogs using jQuery. Check it out:
http://myclabs.github.io/jquery.confirm/[^].

If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com/[^],
http://learn.jquery.com/[^],
http://learn.jquery.com/using-jquery-core/[^],
http://learn.jquery.com/about-jquery/how-jquery-works/[^] (start from here).

Your question about "onclienclick" looks irrelevant to me, I cannot even understand your idea. You need to get confirmation on the client side anyway. You don't have to use ASP.NET code behind to add an event handler, you generate some HTML, and it can contain any JavaScript.

[EDIT]

In response to the OP's comment to this answers:

The answer is in this comment. Note that his event can be cancelled:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewdeleteeventargs.aspx[^],
http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel.aspx[^].

—SA


<asp:imagebutton id="ImageButton1" runat="server">
             ImageUrl ="~/images/grdbtndelete.png" CommandName ="Delete" 
OnClientClick="return confirm("Are you sure you want to delete this entry?");"  />
</asp:imagebutton>


这篇关于需要javascript代码来确认删除按钮删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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