Search code examples
c#.neteventvalidation

Invalid postback or callback argument. Event validation requires unnecessary "using System.Web.UI"


I have a page with a bunch of text inputs, dropdowns, and buttons. All manipulation of the inputs is done server side. Javascript only adds event listeners which manipulate the contents of the text inputs.

When I remove the unnecessary (dimmed)

using System.Web.UI

I get the annoying "Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation=\"true\"/> in configuration or <%@ Page EnableEventValidation=\"true\" %> in a page. ...

When I put it back in the problem goes away.

enter image description here

Removing javascript and all processing in Page_Load does not make the problem go away.

How weird is that? What is going on here?


Solution

  • Turns out it was caused by a line break in a <asp:ListItem>Big long item with a line break</asp:ListItem>.

    Presumably, when the item with the line break was selected, the returned HTML no longer matched the source (since line breaks are converted to a space character).