列表框元素使用JavaScript重新安排回发导致事件验证错误 [英] ListBox elements rearranged with JavaScript causing event validation error on postback

查看:227
本文介绍了列表框元素使用JavaScript重新安排回发导致事件验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了交换技术控制包括两个列表框和一些按钮,让我来交换这两个列表之间项目的项目。该交换是使用JavaScript实现。我也移动项目并在列表中上下。基本上,当我移动到项目列表框右边我存储在一个hiddenfield元素(GUID)的的datakeys。在回发我只是读从外地的GUID。一切都很正常,但在回发,我得到以下异常:

I have created an item swapper control consisting in two listboxes and some buttons that allow me to swap items between the two lists. The swapping is done using javascript. I also move items up and down in the list. Basically when I move the items to the list box on the right I store the datakeys of the elements (GUIDs) in a hiddenfield. On postback I simply read the GUIDs from the field. Everything works great but on postback, I get the following exception:

无效的回发或回调参数。在一个页%@页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.

我已经prepared测试应用程序。所有你需要做的就是下载压缩文件并运行项目。在网页中选择3项,preSS添加所有,然后将第三个元素上一级,然后点击按钮。该错误会出现。谈及事件验证了绝不是可以接受的。谁能帮我,我花了两天已经几天没有找到一个解决办法。

I've prepared a test application. All you have to do is download the archive and run the project. On the web page select the 3 items, press Add all, then move the third element up one level and then hit "Button". The error will show up. Turning event validation off is by no means acceptable. Can anyone help me, I've spent two already days without finding a solution.

测试应用程序

推荐答案

第一个选项会带来相当大的开销。我已经定义从列表框中类派生自己的自定义列表框控件并进行了loadpostback数据的覆盖:

The first option will bring considerable overhead. I have defined my own custom listbox control derived from the listbox class and performed an override of the loadpostback data:

public class CustomListBox : ListBox
{
    protected override bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
    {
        return true;
    }
}

使用这个,而不是我的用户控制的常规列表框解决了这个问题,但是都没有用我的方法相关联的所有风险?

Using this instead of the regular listbox in my user control solved the problem, however are there any risks associated with my approach?

这篇关于列表框元素使用JavaScript重新安排回发导致事件验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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