Search This Blog

Friday, July 8, 2011

ASP.NET "Invalid postback or callback argument. Event validation is enabled ..." error

I'm working on a page which features a user control which contains a datagrid with "Select" buttons in each row.

During initial development of the page the same datagrid was placed directly in the content section of a page and its behavior was normal; when this datagrid and other controls were put into a user control and the user control added to the page I began getting this error;

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

I checked to make sure that the user control was registered in the page that was hosting it -- it was -- so I was a little puzzled at why the host page wasn't recognizing the user control.

Googling the problem turned up a lot of responses saying that changes could be made in the config file to turn off this security feature but this seemed a little kludgy.

Tracing the problem in the debugger I found that the failure was occuring during the Page_Load event in the page lifecycle of the user control and failing on the code in that event handler. I moved the code that was in the "Page_Load" event handler into the 'Page_Prerender" event handler and this problem stopped.

I am not quite sure why this worked, I'll write a comment to this blog entry if I figure it out.

1 comment:

David Graper said...

Here's a webpage with a relevant clue in it by a contributor named 'Burda':

http://www.c-sharpcorner.com/Forums/Thread/35301/invalid-postback-or-callback-argument-event-validatio.aspx