0

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();`
user175084
  • 4,550
  • 28
  • 114
  • 169
  • 1
    can you let us know what type of error you're receiving? maybe a stack trace and some code? – user10635 Dec 17 '09 at 19:45
  • 1
    Generally, pressing the back button will show a cached copy of a page (since the browser usually caches). Doing a sort should work if you keep your bound data in the viewstate. Further you could use fiddler and examine the request before and after the back button to see that they are the same. – Mikael Svenson Dec 17 '09 at 20:53

1 Answers1

0

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
  • 13,219
  • 9
  • 52
  • 62