Maintain scroll position on postback in asp.net

In this programming tutorial we will learn how to maintain scroll position on postback in asp.net. Normally when Postback is fired, the focus of page sets to the top position of the current page. User has to scroll down manually on the location of the web page where he was at last time before postback is fired.

Page.MaintainScrollPositionOnPostBack Property is used to get or set the position of page after Postback is fired.

Page.MaintainScrollPositionOnPostBack is supported in frameworks greater than equal to 2.0

You can add the following line on Page directive for a single page to maintain the previous scroll position on post back.
<%@ MaintainScrollPositionOnPostback="true" %>
Or you can add following line to the c# code behind of your asp.net page
Page.MaintainScrollPositionOnPostBack =true;
You can add following settings on Web.Config file for all pages of your website to maintain the previous scroll position when Postback is fired.
<configuration>
   <system.web>
      <pages maintainScrollPositionOnPostBack="true" />
   </system.web>
</configuration>

So that's it.
I Love your feedback.

0 comments: