views:

1295

answers:

8

I'm writing a simple photo album app using ASP.NET Ajax.
The app uses async Ajax calls to pre-load the next photo in the album, without changing the URL in the browser.

The problem is that when the user clicks the back button in the browser, the app doesn't go back to the previous photo, instead, it navigates to the home page of the application.

Is there a way to trick the browser into adding each Ajax call to the browsing history?

+4  A: 

MSDN has an article about Managing Browser History in ASP.NET AJAX

Espo
The above link is no longer working.
Keltex
@Keltex I have replaced the link with a link to MSDN now. Thanks :)
Espo
+2  A: 

Many websites make use of a hidden iframe to do this, simply refresh the iframe with the new URL, which adds it to the browsing history. Then all you have to do is handle how your application reacts to those 'back button' events - you'll either need to detect the state/location of the iframe, or refresh the page using that URL.

James Burgess
A: 

The 3.5 SP1 update has support for browser history and back button in ASP.NET ajax now.

Will
A: 

For all solutions about the back button, none of them are "automatic". With every single one you are going to have to do some work to persist the state of the page. So no, there isn't a way to "trick" the browser, but there are some great libraries out there that help you with the back button.

Darren Kopp
A: 

Info: Ajax Navigation is a regular feature of the upcoming IE8.

entropia
Interesting. Thanks!
Alexander Prokofyev
A: 

Follow the article "AJAX: How to Handle Bookmarks and Back Buttons" HERE

A: 

Came across this recently which solves the problem with four client side scripts.

cfeduke
A: 

The answer for this question will be more or less the same as my answers for these questions:

In summary, you'll definitely want to check out these two projects which explain the whole hashchange process and adding ajax to the mix:

  • jQuery History (using hashes to manage your pages state and bind to changes to update your page).

  • jQuery Ajaxy (ajax extension for jQuery History, to allow for complete ajax websites while being completely unobtrusive and gracefully degradable).

balupton