.net – 带有数据绑定控件的“无效的回发或回调参数”

当我的数据绑定控件发生事件(添加/编辑/删除)时,我收到以下错误.

Invalid postback or callback argument.
Event validation is enabled using in
configuration or <%@ Page
EnableEventValidation=”true” %> in a
page. For security purposes,this
feature verifies that arguments to
postback or callback events originate
from the server control that
originally rendered them. If the data
is valid and expected,use the
ClientScriptManager.RegisterForEventValidation
method in order to register the
postback or callback data for
validation.

我正在使用自定义的DataList控件,但是GridView,DetailsView,FormView和Repeater控件(也可能与其他数据绑定控件)也会出现此问题.

我可以找到的答案告诉我关闭配置文件页面中的验证,但这听起来不是最好的解决方案.我究竟做错了什么?

解决方法

问题是在页面加载事件中加载控件的数据并调用DataBind()方法.但是,如果在引发事件之前调用DataBind()方法,则会在控件命名已更改时生成上述异常.

解决方案是将其更改为if(!IsPostback)DataBind(),然后在事件处理程序的末尾调用DataBind()方法.无论如何,您需要在处理程序结束时大部分时间调用它来影响更改.

如果这不是您的问题,并且您正在使用JavaScript修改控件客户端,请查看this article.

这是一个自我回答的帖子,因为我在我的博客上收到了很多回应,并且认为我可能会进一步分享.

相关文章

ASP.NET与IIS是紧密联系的,由于IIS6.0与IIS7.0的工作方式的...
在之前的ASP.NET是如何在IIS下工作的这篇文章中介绍了ASP.NE...
这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...