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 postback 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 ajax update panel then you don't have to worry about this. But in case you have not use ajax update panel, then scroll position of the page will not be maintained.

So how we can achieve this?
I know some people will implement this by applying 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

Comments

Popular