David Huby’s Blog Technical and business stuff

2Mar/100

Event validation error in ASP.NET

I ran into this .NET error yesterday:

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.

This article may help if you have a page where the contents of drop down list boxes are being updated after the page has loaded - i.e. with JavaScript.

As K Scott Allen says, "Event validation checks the incoming values in a POST to ensure the values are known, good values. If the runtime sees a value it doesn’t know about, it throws an exception." http://odetocode.com/blogs/scott/archive/2006/03/20/asp-net-event-validation-and-invalid-callback-or-postback-argument.aspx

I had two Drop Down Lists which were being populated via AJAX after page load. The approaches to solving eventValidation errors I saw around on the .NET and StackOverflow:

  • Disable event validation: bad unless you have a workaround for all elements on the page, and some users have said that this has stopped other events firing.
  • Update the Render method: in some cases this will definitely work, in my case - it may be possible that I could have updated the validation with all possible values, something I haven't tried
  • Replace DropDownList controls with select tags: probably not a good idea but could be used for a quick fix
  • Some users have recommended adding an ASP.NET AJAX UpdatePanel around the affected control(s)

In my case I added all possible values of the drop down on page load and removed the AJAX functionality, as a quick fix, because the issue was occurring on a production site.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.