I am trying to extend the gridview functionality in ASP.NET to show 2 images in the header row when sorting is allowed for each column. I receive the following error:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: 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.
Here is a snipped of my server control:
protected override void OnRowCreated(GridViewRowEventArgs e)
{
//if columns not auto-generated and sorting allowed...
if (!this.AutoGenerateColumns && this.AllowSorting)
{
ImageButton imgBtn = new ImageButton();
imgBtn.ID = "imgBtn_" + strSort + "_ASC_" + i.ToString();
imgBtn.ImageUrl = this.Custom_SortImageASC;
imgBtn.ToolTip = "Sort Ascending";
imgBtn.CommandArgument = strSort;
imgBtn.Command += new CommandEventHandler(this.SortByImageASC);
row.Cells[i].Controls.Add(imgBtn);
}
base.OnRowCreated(e);
}
And the 2 methods that handle the image button clicks:
protected void SortByImageASC(object sender, CommandEventArgs e)
{
this.Sort(e.CommandArgument.ToString(), System.Web.UI.WebControls.SortDirection.Ascending);
}
protected void SortByImageDESC(object sender, CommandEventArgs e)
{
this.Sort(e.CommandArgument.ToString(), System.Web.UI.WebControls.SortDirection.Descending);
}
Any idea why this won't work? If I turn off event validation, it works. But, I don't want to do that because this may be on many pages eventually.
EDIT: BY THE WAY -- THIS IS IN AN UPDATE PANEL IF THAT MAKES A DIFFERENCE.