问题描述
我创建了一个包含两个列表框和一些按钮的项目交换器控件,这些按钮允许我在两个列表之间交换项目.交换是使用javascript完成的.我还在列表中上下移动项目.基本上,当我将项目移动到右侧的列表框时,我将元素(GUID)的数据键存储在隐藏字段中.在回发时,我只是从现场读取 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:
回发或回调参数无效.使用配置中或页面中的 <%@ Page EnableEventValidation="true" %> 启用事件验证.出于安全目的,此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件.如果数据有效且符合预期,请使用 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.
我已经准备了一个测试应用程序.您所要做的就是下载存档并运行项目.在网页上选择 3 个项目,按全部添加,然后将第三个元素上移一级,然后点击按钮".错误会出现.关闭事件验证是绝对不能接受的.谁能帮帮我,我已经花了两天时间没有找到解决方案.
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 重新排列的 ListBox 元素导致回发时发生事件验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!