ASP.NET Futures (July 2007): Managing Browser History and Back Button Support in ASP.NET AJAX
This section provides information about the following features::
- History and book marking. You can manage history points in your application, which lets users click the browser's Back and Forward buttons to navigate logically through your application instead of browsing to other pages.
- The
Historyserver control. This control lets you manage application history and use theNavigateevent in the server and client. - The client
Sys.Applicationobject. This object lets you set history points. It also calls thepageNavigatefunction.
ASP.NET Futures (July 2007) release The following changes and additions have been introduced:
- History is now supported for the Apple Safari browser.
- Any state that is provided through the server is encoded and can be encrypted.
- You can define titles for individual history entries to be able to specify the page title used in the browser's history list.
- You can use history support entirely in the client, without the need for a server control.
History Management with Server Controls:
Server-based history management is provided by the History Web server control. This control enables you to handle server events as you normally do in postback scenarios and to set a history point on the control. At the history point you define an object or data (that is, state) that will be used to recreate your page when a navigation event is raised. When you create history points, the page's URL is appended with the serialized and encrypted data that is required to recreate the state of the page. This also creates an entry in the browser's history stack.
When users click the browser's Back button, the browser navigates through previously-viewed URLs, which will include URLs that contain history-point data. A Navigate event is raised for the History control; the event data includes the data appended to the URL. This enables you to handle the event and recreate the page state as required in your application.
The following example uses the UpdatePanel control for asynchronous postbacks. The History control is used to add history points during the Click event handler of the buttons that trigger the asynchronous postbacks. As a result, when you click the browser's Back button, you do not leave the Web page, but instead navigate through the previous UpdatePanel postbacks.
Enabling Permalinks to Page State
You can enable users to set a permalink to a specific state of the page. This means that they can bookmark a particular point in your application and then set the page with that state as a favorite or email the permalink URL so that the specific page state can be recreated.
To enable users to create a permalink, you can get the current state by using the Sys.Application.get_history().get_stateString() in client script, and History.getStateString() in server code. The following example shows how to create a permalink for a specific state through client-side JavaScript code.
Managing the Title of a History Entry
Typically, entries in the browser's history stack are identified by the title of the page for that entry. (To see an example of this, use the browser's recent-pages drop-down list to view the titles.) By default, when you create history entries in your application as described previously, the page's title is used to identify a history-state entry. However, you can provide meaningful titles for individual history entries. The following sample shows how to perform this task. In the client, add a title parameter when you call the Sys.Application.get_history().addHistoryPoint( ) method. In server code, you can add a title when you call the History.AddHistoryPoint( ) method.
No comments:
Post a Comment