I have a simple page that, on the initial load, databinds to a GridView. This gridview has sorting and paging enabled, and is also surrounded by an UpdatePanel.
When the user does the following, I receive this error:
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.
- Clicks the pager to change to a specific page (lets say 5)
- Clicks on a link to navigate to another page
- Presses the back button in their browser to return to the page with the GridView
- Grid is now reverted back to it's original state (on page 1) since the browser didn't track that, and so the user clicks to go to page 5 again, resulting in the error
Anyone know what would cause this? It only seems to be a problem when clicking on the same page. If a different page is clicked on the return visit, it's fine. If a column is sorted, then sorted again on the return visit, that is also fine. I'm not sure what specifically about clicking the page twice is causing the problem.
Here's the code for the pager:
protected void gvResults_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvResults.DataSource = SearchResults;
gvResults.PageIndex = e.NewPageIndex;
gvResults.DataBind();
}
where gvResults is the GridView, and 'SearchResults' is a List stored in the viewstate.
edit
It appears that although the gridview isn't displaying page 5 when the user returns to the page (reverts back to page 1), for some reason the browser did save the viewstate, and has the gridview at page 5. So if I click on page 4 and go through the code for the paging event, I can see that it thinks the page it was on was 5... even though the displayed content was for page 1.
Moral of the story is apparently the viewstate is getting saved when the user clicks the back button to return to the page, but the displayed table is not.