jump to navigation

Maintaining scroll position in ASP.Net applications March 7, 2010

Posted by fofo in asp.net.
Tags:
trackback

One of the most common questions I get is ” How to maintain the scroll position-location when a postback occurs in our ASP.NET application? ”

A lot of times when  we click on a e.g a button in our application and a postback occurs, our application “loses” its scroll position.

The default behaviour is to go back to the top of the page.

There is a very nice feature in ASP.NET that enables us to maintain the scroll position in ASP.NET.

The name of this attribute is MaintainScrollPositionOnPostBack.

We can set the  MaintainScrollPositionOnPostBack=”true”

we can do that within the Page directive e.g

<% Page Language =”C#” MaintainScrollPositionOnPostBack=”true” %>

So now the browser remembers where it was before the post back occured and knows how to keep track of the scroll position.

This is of course achieved with client-side Javascript code that it is injected into the page for us.

So if you go to View –>Source in your browser window, you will see the generated Javascript code.

Hope it helps!!!!

Comments»

1. Scroll dotnet | Hbeletric - March 30, 2012

[…] Maintaining scroll position in ASP.Net applications « DOT NET RULESMar 7, 2010 … One of the most common questions I get is ” How to maintain the scroll position- location when a postback occurs in our ASP.NET application? “ … […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: