Prevent browser from scrolling after ajax postback

If you are building an application that uses the MS Ajax Framework (which the Telerik AJAX controls are built on) you may have noticed that if you are doing background updates that the user experience can become quite jarring in terms of page scrolling.

The framework as standard will store (client side) the scroll position of the page when an Ajax request is made, when the request returns it will set the scroll position back to where it was when the initial request was made.

This might be a desirable feature for some AJAX applications but if you like myself are doing background work with AJAX requests this can be frustrating.

I’ve found a way to turn the feature off, it is a bit of a hack but it works well. Drop the following JavaScript into your pages doing background Ajax calls.

// Prevent MS Ajax from changing scroll position after ajax postback.  
function scrollTo(x,y) {}  

Solution source: Telerik Forums


Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

Leave a Reply

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

You are commenting using your 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