微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.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.

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐