Tuesday, July 29, 2008

Using Back Button in ASP.NET 2.0 Ajax

One problem faced by a typical AJAX application is that a partial page update is not added to the history of the Web browser. This means that the browser’s Back button does not move back one AJAX step, but moves back one entire document, which is unlikely to be what the user expects. 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":.

private void ContentList_SelectedIndexChanged(object sender,

EventArgs e)



private void HistoryControl_Navigate(object sender, HistoryEventArgs e)

int selectedIndex = 0;
    if (String.IsNullOrEmpty(e.Identifier) == false) {
        selectedIndex = Int32.Parse(e.Identifier);
// Update the content being displayed in the page
contentList.SelectedIndex = selectedIndex;
// Mark the update panels as needing an update




Post a Comment