如何在命令字段中添加onclick事件? [英] how to add onclick event to command field?

查看:90
本文介绍了如何在命令字段中添加onclick事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我需要这里的帮助

我在gridview中有此删除按钮

Hi all

I need some help here

I have this delete button in gridview

<asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/remove.png"
                DeleteText="" ShowDeleteButton="True" />



如何将OnClick事件处理程序添加到此按钮

以及如何从按钮存在的行中获取ID



非常感谢你.



how to add OnClick event handler to this button

and How to get the id from the row which the button exist



thank you so much

推荐答案

看,你有完全不同的问题,问/发问题的方式也不同.您正在尝试解决其他问题.

现在,可能有几个原因导致您遇到此问题.简单/直接的解决方案可以在您的Page指令或Web.config文件中添加enableEventValidation="false".

但是,找到根本原因总是好的.可能是您在每次回发时都重新绑定了网格.因此,在RowCommand触发之前,您的GridView将重新绑定,并且其中的所有控件都将分配给新的ID.因此RowCommand无法获得触发该事件的物品.为避免这种情况,您需要做的就是将网格绑定线置于IsPostBack条件.
See, you have entirely different issue and the way you asked/posted question was in different direction. You were trying to solve for something else.

Now, there could be few reasons why you are getting this issue. Easy/direct solution can be adding enableEventValidation="false" in your Page directive or Web.config file.

But, it is always good to hit the root cause. It might be that you are rebinding your grid on every postback. Thus, before RowCommand fire your GridView will rebind and all control within it will be assigned to new id. So RowCommand could not get the item which have fired the event. To avoid this, all you need to do is put your grid bind line in IsPostBack condition.
if (!IsPostBack)
{
      //Your code for Bind data
}



此处的详细说明:无效的回发或回调参数解决方案.事件验证... [ ^ ]

有趣的是阅读一个与此相关的博客条目: [



Detailed explanation here: Invalid postback or callback argument solution. Event validation...[^]

Interesting to read one blog entry related to same: "Invalid postback or callback argument" in ASP.NET[^] - It exposes few other reasons on why one can get the same error. Nice read.


这篇关于如何在命令字段中添加onclick事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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