Article ID: 913721 - View products that this article applies to.
Smart navigation is deprecated in Microsoft ASP.NET 2.0 and is no longer supported by Microsoft Product Support Services. This article describes how to implement the smart navigation features in ASP.NET 2.0.
In earlier versions of ASP.NET, you enable smart navigation by using the Page.SmartNavigation property. When you set the Page.SmartNavigation property to true, the following smart navigation features are enabled:
How to maintain the scroll positionTo maintain the scroll position of a Web page after postback, use the Page.MaintainScrollPositionOnPostBack property. For more information about the Page.MaintainScrollPositionOnPostBack property, visit the following Microsoft Developer Network (MSDN) Web site:
How to maintain the element focusTo maintain the element focus on a Web page during navigation, use the Page.SetFocus method. For more information about the Page.SetFocus method, visit the following MSDN Web site:
How to retain only the most recent Web page state in the Web browser history folderTo prevent a user from going back to previously visited Web pages, you must prevent visited Web pages from being added to the Web browser history folder. Additionally, you must prevent postbacks that are generated by ASP.NET server controls from being added to the Web browser history folder. If only the most recent Web page state is retained, and if no Web pages are in the Web browser history folder, Back is unavailable.
By design, you cannot modify the Web browser history folder programmatically. To work around this restriction, use one of the following methods.
Method 1: Disable the Web browser cache, and use session variablesIf you disable the Web browser cache, Microsoft Internet Explorer retains only pointers to the visited Web pages in the Web browser history folder. Internet Explorer does not retain the actual content for the Web pages. Therefore, when a user clicks Back, the Web browser must submit a page request to the Web server. By using ASP.NET session variables, you can write an algorithm that determines whether the user should be able to view the requested page. If problems would occur in the Web application when a user viewed the requested page, the Web server can redirect the Web browser to the current page instead. Therefore, nothing appears to happen when the user clicks Back.
To disable the Web browser cache, use one of the following methods:
Method 2: Use a hidden frame in a Web pageThis method resembles the mechanism that is used internally by smart navigation. Create a Web page that contains a visible frame and a hidden frame. The following HTML code example demonstrates how to do this.
Both frames must reference an existing Web page. Otherwise, the Web browser window displays an error message that the Web page cannot be found. The hidden frame page (Fillerpage.html) must contain no content. The visible frame page (Goback.html) must contain the following HTML code.
When a user visits the Web page, both frames are loaded. The Goback.html page immediately redirects the visible frame to a new Web page (Nobackpage.html). If the user clicks Back, the Goback.html page is loaded. Then, the Goback.html page immediately redirects the user to the Nobackpage.html page again.
Method 3: Use the location.replace methodCreate a Web page that runs a client-side script that calls the location.replace method. In this case, the Web browser loads the content of a URL in the active window. Because the content is replaced in the active window, the Web browser does not consider this replacement to be navigation between Web pages. Therefore, no entries are added to the Web browser history folder. The following HTML code example demonstrates how to use the location.replace method.
The following code example demonstrates how to use the location.replace method in a C# method.
For more information about the location.replace method, visit the following MSDN Web site:
Method 4: Use the window.history.forward methodCreate a Web page that runs a client-side script that calls the window.history.forward method. In this case, the Web browser automatically advances one page in the Web browser history folder. Therefore, later postbacks are added to the Web browser history folder. If a user clicks Back, the user is redirected to the current Web page.
You can use the window.history.forward method together with the location.replace method. When you use these methods together, navigation between Web pages and postbacks are handled correctly.
For more information about the window.history.forward method, visit the following MSDN Web site:
Method 5: Modify the Web application logicModify the Web application logic to work correctly when a user clicks Back. The Web application must maintain the integrity of all the submitted data and the integrity of the user state when the user clicks Back.
How to minimize the flicker effect that may occur during navigationWhen a user views a Web page in an ASP.NET Web application that uses server controls, the user may experience a flicker effect. The flicker effect may occur when the user changes the value of a control. If the control generates a postback, the Web browser submits a request for a new Web page state to the Web server. When the new Web page state is rendered in the Web browser, the flicker effect may occur.
There are no simple ways to eliminate this flicker effect, because the Web page must be rendered again. Typically, this behavior is noticeable to the user.
Note When the connection speed between the Web client and the Web server is very fast, the flicker effect may be unnoticeable.
To minimize the flicker effect, minimize the number of postbacks, or eliminate postbacks. To do this, use one of the following methods, as appropriate for your situation.
Method 1: Use the ASP.NET 2.0 client callback managerUse the ASP.NET 2.0 client callback manager to let Web pages submit requests to the Web server without using a full postback. Because the client callbacks do not include postback data, the client callbacks do not force the whole Web page to be updated in the Web browser. This minimizes the flicker effect that may occur during navigation.
For more information about the ASP.NET 2.0 client callback manager, visit the following MSDN Web site:
http://msdn.microsoft.com/msdnmag/issues/06/00/ASPNET20Overview/default.aspxFor more information about how to implement client callbacks without using a postback, visit the following MSDN Web site:
Method 2: Use a hidden frame in a Web pageCreate a Web page that contains a visible frame and a hidden frame. For more information about how to do this, see method 2 in the "How to retain only the most recent Web page state in the Web browser history folder" section.
For more information about the Page.SmartNavigation property that is deprecated in ASP.NET 2.0, visit the following MSDN Web site:
Article ID: 913721 - Last Review: November 22, 2007 - Revision: 1.4