An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

SmartNavigation to maintain scroll position across postbacks

Monday, April 25, 2005 7:52 AM

SmartNavigation is no longer a recommended practice with newer techniques like ASP.NET AJAX, providing better user experiences

This article describes about using the Smart Navigation property to maintain the scroll position of pages across postbacks.

All of us know that asp.net controls postback to the server and hence the page is reloaded everytime an event is triggered.

Supposing we have a very long page with lots of controls. A user is in the middle of the page and triggers an event (say click event), which causes the page to postback. Then the page will be reloaded and the position would go to the top.

This could be particularly annoying if the user has to scroll down long and repetitively.

To avoid this, ASP.NET provides the SmartNavigation property for the page which takes care of the scroll position.

SmartNavigation also avoids the flickering of the page when the page is reloaded.

It can be enabled by simply setting its value to true in the page directive, as follows:-

<%Page smartNavigation="True" %>

Alternatively, it can be specified as a global setting in the web.config as follows:-

<configuration>
<system.web>
<pages smartNavigation="true"/>
</system.web>
</configuration>

This would apply for all the pages that fall under the web.config's settings.

This is a wonderful mechanism particularly if you have lengthy pages and repetitive server side interactions.

This works only for Internet Explorer browsers and for Netscape, it is simply turned off automatically.

Another issue that may arise is when using javascript and dhtml scripts as they will not be rendered again while using smartnavigation.


Feedback

# re: SmartNavigation to maintain scroll position across postbacks

Thank you very much. I tried altering some autoscroll scripts I found on the web, but figured there had to be an easier way to do it, without the need to register another client script. 7/18/2005 7:25 PM | Willie Williams

# re: SmartNavigation to maintain scroll position across postbacks

This gave me that what i have expected. previously i did this but i forgot the and found from your URL. Thank you very much. 3/14/2006 10:50 PM | Sathya

# re: SmartNavigation to maintain scroll position across postbacks

protected void Page_Load(object sender, EventArgs e)
{

MaintainScrollPositionOnPostBack = true;

} 7/1/2006 12:33 AM | stephen

# re: SmartNavigation to maintain scroll position across postbacks

Thanks that was very useful. But the font size changes. Is there any way to retain? 11/7/2006 10:38 AM | TIG

# re: SmartNavigation to maintain scroll position across postbacks

Thank U very much 12/2/2006 4:15 AM | Mohan

# re: SmartNavigation to maintain scroll position across postbacks

"Another issue that may arise is when using javascript and dhtml scripts as they will not be rendered again while using smartnavigation"
can you please explain this to me, i mean to say that I am very well aware of dhtml and javascript but can you tell me, how critical it can be and why is that so 8/7/2007 5:15 PM | arfeen

Post a comment





 

Please add 2 and 1 and type the answer here: