CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

SmartNavigation has Internet Explorer displaying the wrong html source

SmartNavigation is a feature which can cause quite a lot of trouble. It is a property of an asp.net webpage intended to improve the "user experience" over postbacks by

  • Maintaining the scroll position in the browser
  • Maintaining the history over pages. Clicking back navigates to the previous page viewed instead of the previous roundtrip of the same page

The feature only works in Internet Explorer and has some bizarre side effects. Navigating to another page from code just does not work right. View source and Save As in IE are a complete WTF. I did write a small entry on that before, had forgotten about it until it hit me again last week.

Here's a web page to demonstrate the problem. It has two panels and a radiobuttonlist to pick which of them will be visible

protected void Page_Load(object sender, EventArgs e)
{
   Panel1.Visible = RadioButtonList1.SelectedIndex == 0;
   Panel2.Visible = RadioButtonList1.SelectedIndex == 1;
}

Panel1 contains a bulletlist, panel2 a calendar. It should be easy to see both in the browser and in the underlying HTML which panel is rendered. The result in IE :

When displaying the source IE will return the HTML of the first roundtrip. This is very clear for the panel; the browser displays panel TWO, the source displays the HTML of panel ONE. You can also spot the differences in the smaller details. The page has a label to display the roundtrip count. In the source the text of this label is always 1.

In VS 2005 the SmartNavigation property is considered obsolete. It still works and does display the same errant behavior. The Page.SetFocus method and Page.MaintainScrollPositionOnPostBack property are proposed as alternative. These do not maintain the history of pages visited. To get that fixed independent of SmartNavigation-settings and browser-brand you'll have to use a custom button. May I suggest this one ?


Published Jan 11 2006, 07:26 AM by pvanooijen
Filed under:

Comments

Jeffrey Palermo said:

That SmartNavigation feature never was of any use. It was very buggy. On some pages, turning on SmartNavigation would break the page's functionality.

With the ease of registering client script, we can more easily add these nice features on our own.
# January 11, 2006 9:01 AM

Geoff Appleby said:

Hey Peter,
I was going to leave a comment to explain why it's not SmartNavigation's fault that the source doens't get updated and that it's a standard IE behaviour, but I figured it warranted a new blog post :)

http://codebetter.com/blogs/geoff.appleby/archive/2006/01/11/136444.aspx
# January 11, 2006 7:27 PM

pvanooijen said:

Thanks Geoff. Great post.
I just have to have to live with smartnav. Afaik it's the only way to make the browser and mouse back buttons work right.
# January 12, 2006 3:22 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!