"回发无效或回调参数"与数据绑定控件 [英] "Invalid postback or callback argument" with Databound controls

查看:134
本文介绍了"回发无效或回调参数"与数据绑定控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个事件(添加/编辑/删除)在我的数据绑定控件时我收到以下错误。

I am getting the following error when an event (Add/Edit/Delete) occurs on my databound control.

无效的回发或回调参数。
  事件验证使用启用
  配置或LT;%@页
  EnableEventValidation =真正的%>在
  页。为了安全起见,这
  功能验证参数
  回发或回调事件的起源
  从服务器控件
  最初呈现这些。如果数据
  是有效的和期望的,可使用
  ClientScriptManager.RegisterForEventValidation
  方法以注册
  对于回发或回调数据
  验证。

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控件(也许与其他数据绑定控件)。

I am using a custom DataList control, but this problem also occurs with GridView, DetailsView, FormView and Repeater control (and maybe with other databound controls).

问题的答案,我可以找到告诉我关掉在配置文件或页面验证,但听起来不像是最好的解决方案。我在做什么错了?

The answers I can find tell me to turn off the validation in the config file or page, but that does not sound like it is the best solution. What am I doing wrong?

推荐答案

问题正在加载数据,在页面Load事件的控制和调用的DataBind()方法。但是看来,如果被升高产生上述异常作为控制命名已经改变之前的事件的的DataBind()方法被调用。

The problem is loading the data for the control in the page Load event and calling the DataBind() method. However it appears that if the DataBind() method is called before the events are raised the above exception is generated as the control naming has changed.

的解决方案是此更改为如果(!的IsPostBack)的DataBind(),然后调用DataBind()方法在事件处理程序的结束。则需要在处理程序结束无论如何称它为大部分时间以影响变化。

The solution is to change this to if(!IsPostback) DataBind() and then call the DataBind() method at the end of the event handler. You would need to call it most of the time anyway at the end of the handler to affect the changes.

如果这不是你的问题,你正在修改控件使用JavaScript客户端,检查出的this文章

If this is not your problem, and you are modifying controls client side using JavaScript, check out this article.

这是一个自回答后,因为我是得到了很多的反应在我的博客对这个问题,我想我可能会进一步分享。

这篇关于&QUOT;回发无效或回调参数&QUOT;与数据绑定控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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