how to maintain scroll position on postback in asp.net using c#

In this web programming tutorial we will learn how to maintain scroll position on postback in asp.net using c#. When Postback event 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 event was fired. in order to do so .NET frame work provides a property that is following,

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

Page.MaintainScrollPositionOnPostBack is supported in frameworks greater than 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" %>  
you can also 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 as well for all pages of your website in order to maintain the previous scroll position when Postback event is fired.

  
     
        
     
  

Admin

A Software Engineer, Social Media Marketing Expert, writer,

Post a Comment

Previous Post Next Post