ButtonField字段点击:前ASP的Javascript [英] Javascript before asp:ButtonField click

查看:322
本文介绍了ButtonField字段点击:前ASP的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Asp.net应用程序中的 GridView控件控制,即有一个< ASP:ButtonField字段> 键入=形象的CommandName =删除

I have a GridView control in an Asp.net application, that has a <asp:buttonField> of type="image" and CommandName="Delete".

有什么办法达到 OnRowDelete 事件之前执行一段JavaScript代码?

Is there any way to execute a piece of javascript before reaching the OnRowDelete event?

我想只是一个简单的确认删除行之前。

I want just a simple confirm before deleting the row.

谢谢!

修改:请注意,&LT; ASP:ButtonField字段&GT; 标签的没有的OnClientClick 属性。

EDIT: Please Note that <asp:ButtonField> tag does not have an OnClientClick attribute.

推荐答案

我会用一个TemplateField,而是和填充的ItemTemplate一个普通的asp:按钮或ASP:ImageButton的,这取决于一个是需要的。然后,您可以执行相同的逻辑的RowCommand事件打算做时,它拦截了删除命令。

I would use a TemplateField instead, and populate the ItemTemplate with a regular asp:Button or asp:ImageButton, depending one what is needed. You can then execute the same logic that the RowCommand event was going to do when it intercepted the Delete command.

在任何这些按钮的我​​会再使用OnClientClick属性来执行JavaScript此之前确认对话框。

On either of those buttons I would then use the OnClientClick property to execute the JavaScript confirm dialog prior to this.

<script type="text/javascript">
   function confirmDelete()
   {
       return confirm("Are you sure you want to delete this?");
   }
</script>

...

<asp:TemplateField>
  <ItemTemplate>
     <asp:ImageButton ID="DeleteButton" runat="server"
        ImageUrl="..." AlternateText="Delete" ToolTip="Delete"
        CommandName="Delete" CommandArgument='<%# Eval("ID") %>'
        OnClientClick="return confirmDelete();" />
  </ItemTemplate>
</asp:TemplateField>

这篇关于ButtonField字段点击:前ASP的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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