ASP.NET MVC3 Razor - maintain scroll position on postback

How can I keep the scroll position after postback after sorting a grid table that uses the MvcContrib structure?

+7
source share
3 answers

The usual way is to use some javascript to set the current scroll position to a hidden field, and then restore that position when the page loads (usually in a jquery ready event).

However, this is really just a side effect. You have to do some ajax command to update the grid, not the postback, then scrolling is not required.

+1
source

Use jQuery cookie and client side.

$(function(){ var posName = location.href + "_top"; $(window).unload(function() { var top = $(document).scrollTop(); $.cookie(posName, top); }); var goTop = parseInt($.cookie(posName)); if (goTop) { $(document).scrollTop(goTop); $.cookie(posName, ""); } }); 

Hope this code.

0
source

A useful solution is published here: http://www.experts-exchange.com/Hardware/Servers/Q_28082177.html

 $(function(){ var top = parseInt($.cookie("top")); if(top) $(document).scrollTop(top); $(document).scroll(function() { var top = $(document).scrollTop(); $.cookie("top", top); }) }); 

This is a very old thread, but I posted it for a developer who will look for such a problem, may help.

0
source

All Articles