使用客户端代码在列表框中进行更改时,单击“保存"按钮时出错 [英] Error when click save button when there's changes in the listbox using client side code

查看:67
本文介绍了使用客户端代码在列表框中进行更改时,单击“保存"按钮时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

前提条件:
1.我有2个列表框1-包含所有项目(来自数据库),另一个包含所选项目(空白)
2. lstAllItems.DataSource = myDataSomething;
3. lstSelectedItem->未填充
4.我有客户端控件btnMove,它将复制lstAllItems列表框中的所选项目并将其复制到lstSelectedItem.负责此操作的代码是客户端代码(javascript)
5.然后点击保存按钮

保存期间遇到2个错误:
1.如果在<%@ Page ...%>中启用EnableEventValidation.我收到此错误:

Hello Guys,

precondition:
1. i have 2 listbox 1-that contains all items (from database) and the other one contains the selected item (blank)
2. lstAllItems.DataSource = myDataSomething;
3. lstSelectedItem -> not populated
4. i have client side control btnMove that will copy the selected item from lstAllItems listbox and copy it to the lstSelectedItem. The code responsible for this is a client side code (javascript)
5. then click save button

I have 2 error encountered during saving:
1. If EnableEventValidation is on in <%@ Page ...%> I am getting this error:

Exception type: ArgumentException
    Exception message: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> 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.



2.如果关闭了EnableEventValidation,并且当我单击保存"按钮时,lstSelectedItem列表框(尽管它是使用JavaScript填充的),但是当我对lstSelectedItem.Items.Counts.Counts.Counts.Counts.Counts.Counts.Counts.Counts.Counts.Counts.Counts.Counts进行计数时,结果为零.
问题: 我阅读了几篇文章,指出要使用GetPostBackEventReference方法,但问题仍然存在.



2. If turned off the EnableEventValidation and when i click save button the lstSelectedItem listbox (though it was populated using javascript) but when i count the items like lstSelectedItem.Items.Count the result is zero.

Question:I read couple of articles stating to use GetPostBackEventReference method but still the issue is still there.

推荐答案


  • 1.在隐藏的文本框中添加到页面,例如(hidtxt runat = server).
  • 2.单击移动按钮时,还应将所选值设置为ListBox asn Hidden Filed,并用逗号分隔.
  • 3..现在,您应该从hidtxt而不是列表框访问服务器端的值
  • 这可以100%解决您的问题.

    谢谢,
    Imdadhusen
Hi Jephunneh Malazarte,

You are right, you are not able to get values from list box which are added from client side (Javascript).

Solution:
just do the following steps:

  • 1. Added on hidden textbox to the page e.g. (hidtxt runat=server).
  • 2. When you click on move button then you should also set the selected value to the ListBox asn Hidden Filed with comma seperated.
  • 3. Now you should access value on server side from hidtxt instead of listbox
  • This is 100% resolve your problem.

    Thanks,
    Imdadhusen


这篇关于使用客户端代码在列表框中进行更改时,单击“保存"按钮时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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