Friday, September 15th, 2006

Enabling Back/Forward-Button Support for ASP.NET AJAX UpdatePanel

Category: .NET, Tip

Scott Guthrie has written up a tip for Enabling Back/Forward-Button Support for ASP.NET AJAX UpdatePanel.

For example, the below code could be written by a developer in response to a selection change within a list to to add the previous list selection to the browser’s history via Nikhil’s “HistoryControl”:


  1. private void ContentList_SelectedIndexChanged(object sender, EventArgs e) {
  2.    history.AddEntry(contentList.SelectedIndex.ToString();
  3. }

Once you add entries into the history control, the back/forward button will be enabled in the browser. Nikhil’s history control then exposes a “Navigate” event which fires when you press the forward or back button in the browser, and this event then exposes the identifier entry provided before when the view was added into the browser history. You can then use this to restore the page to whatever state it should be in to match the previous history item and update the page:


  1. private void HistoryControl_Navigate(object sender, HistoryEventArgs e) {
  3.     int selectedIndex = 0;
  5.     if (String.IsNullOrEmpty(e.Identifier) == false) {
  6.         selectedIndex = Int32.Parse(e.Identifier);
  7.     }
  9.     // Update the content being displayed in the page
  10.     contentList.SelectedIndex = selectedIndex;
  12.     // Mark the update panels as needing an update
  13.     mainUpdatePanel.Update();
  14. }

Download the code for Nikhil’s history control and start using it here

Posted by Dion Almaer at 11:19 am

3.2 rating from 50 votes


Comments feed TrackBack URI

The horizontal scrolling where you show javascript is not working for me.
(I use firefox)

Comment by NNM — August 7, 2007

Leave a comment

You must be logged in to post a comment.