加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 23:30:26 所属栏目:asp.Net 来源:网络整理
导读:当我的数据绑定控件发生事件(添加/编辑/删除)时,我收到以下错误. Invalid postback or callback argument. Event validation is enabled using in configuration or %@ Page EnableEventValidation=”true” % in a page. For security purposes,this featur
当我的数据绑定控件发生事件(添加/编辑/删除)时,我收到以下错误.

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.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读