Invalid postback or callback argument. Event validation is enabled using ''

后端 未结 30 2079
生来不讨喜
生来不讨喜 2020-11-22 05:08

I am getting the following error when I post back a page from the client-side. I have JavaScript code that modifies an asp:ListBox on the client side.

How do we fix

30条回答
  •  星月不相逢
    2020-11-22 05:31

    You are really going to want to do 2 or 3, don't disable event validation.

    There are two main problems with adding items to an asp:listbox client side.

    • The first is that it interferes with event validation. What came back to the server is not what it sent down.

    • The second is that even if you disable event validation, when your page gets posted back the items in the listbox will be rebuilt from the viewstate, so any changes you made on the client are lost. The reason for this is that a asp.net does not expect the contents of a listbox to be modified on the client, it only expects a selection to be made, so it discards any changes you might have made.

    The best option is most likely to use an update panel as has been recommended. Another option, if you really need to do this client side, is to use a plain old . Then, of course, you have to split that again on the server and do something with your items, since your select is empty now that it's back on the server.

    All in all it's a pretty cumbersome solution that I would not really recommend, but if you really have to do client-side modifications of a listBox, it does work. I would really recommend you look into an updatePanel before going this route, however.

提交回复
热议问题