vedi se ti puo' essere d'aiuto questo calvario: (da stackoverflow)

I had an experience with DataGrid. One of it's columns was "Select" button. When I was clicking "Select" button of any row I had received this error message:

"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 changed several codes, and finally I succeeded. My experience route:


1) I changed page attribute to EnableEventValidation="false". But it didn't work. (not only is this dangerous for security reason, my event handler wasn't called: void Grid_SelectedIndexChanged(object sender, EventArgs e)


2) I implemented ClientScript.RegisterForEventValidation in Render method. But it didn't work.


protected
overridevoidRender(HtmlTextWriter writer)
{
foreach(DataGridItem item inthis.Grid.Items)
{
Page.ClientScript.RegisterForEventValidation(item.UniqueID);
foreach(TableCell cell in(item asTableRow).Cells)
{
Page.ClientScript.RegisterForEventValidation(cell.UniqueID);
foreach(System.Web.UI.Control control in cell.Controls)
{
if(control isButton)
Page.ClientScript.RegisterForEventValidation(control.UniqueID);
}
}
}
}

3) I changed my button type in grid column from PushButton to LinkButton. It worked! ("ButtonType="LinkButton"). I think if you can change your button to other controls like "LinkButton" in other cases, it would work properly.