How to maintain page scroll position after page post back in asp.net

In this blog, I will write about How to maintain page scroll position after page post back in ASP.Net.
Suppose there is a page with a huge number of inputs and in one case some error/exception occurs at bottom of the page. But in the postback, the page scroll position moved to the top.

In this case, it is very difficult for a user to identify the error and error location on the page.
If you have used the Ajax update panel then you don’t have to worry about this. But in case you have not used the Ajax update panel, then the scroll position of the page will not be maintained.

So how we can achieve this?
I know some people will implement this by applying a few lines of JQuery or JavaScript.

But don’t worry, ASP.Net has already provided the solution for this.

You just add MaintainScrollPositionOnPostback to true in Page directive and you are done with the solutions.

See below line:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Home.aspx.cs" Inherits="Home" MaintainScrollPositionOnPostback="true" %>

Add this and try to make a postback request on the page and see the difference.

Keep following SharePointCafe.Net

Leave a Comment

RSS
YouTube
YouTube
Instagram