Invalid postback or callback argument…


I started getting this error message:

Invalid postback or callback argument. Event validation is enabled using in configuration or 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.

I am once again working on my ASP.NET Dynamic Data Entities web application (updated to ASP.NET 4.5 and Unity 3 beta), and after adding localization and applying the MVP pattern to the page and field templates, the above error started occurring. Now, I Bing’ed it, but none of the suggestions I came across did anything to alleviate the problem. I had the issue with the ListDetails.aspx Dynamic Data page template every time I used the pager associated with the GridView control, and I begun by looking at the recent application of the MVP pattern, but that didn’t get me any closer to a solution. I then started looking at how I localized the page template and much to my surprise it was caused by disabling viewstate (ViewStateMode="Disabled") for the UpdatePanel control, in which the GridView was contained.

The solution was to enable viewstate (removing the attribute ViewStateMode="Disabled") for the UpdatePanel control and applying it to the QueryExtender control associated with the GridView, as well as all of the controls in the div element with a class of DD.

UPDATE (March 30th, 2013):

Turns out this causes too much hassle with view state turned off, so I have turned it back on, and added a Response.Redirect in the event handlers for changing languages. It’s an extra roundtrip, but it is so much more elegant, especially seen form the users perspective.

Advertisements