views:

131

answers:

1

I have a dynamically generated gridview on page with sorting provided in the code behind also. Now i move from page A to page B using a link, this also works fine. But when i press the browser back button and come back to my page A and again try to sort... page A throws an exception...

is there a way to program this back button like we program a button normally..

Thanks

` Cannot find column machinename. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 Exception Details: System.IndexOutOfRangeException: Cannot find column machinename.

Source Error:

Line 519:                
Line 520:                //Sort the data.
Line 521:                dt.DefaultView.Sort = e.SortExpression + " " +       GetSortDirection(e.SortExpression);
Line 522:                GridView1.DataSource = Session["TaskTable"];
Line 523:                GridView1.DataBind();`
A: 

Page A is probably cached in your browser. You get this cached version when clicking back. Try forcing the browser not to cache the page in the the code behind (of page A) with:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now - new TimeSpan(1, 0, 0));
Response.Cache.SetLastModified(DateTime.Now);
Response.Cache.SetAllowResponseInBrowserHistory(false);
BritishDeveloper