How to maintain scroll position on autopostback?

前端 未结 12 1749
臣服心动
臣服心动 2020-12-30 21:49

How can I get back to the same position of a page on postback. It always seems to get to the top of the page.

I\'ve tried using maintainSc

12条回答
  •  悲哀的现实
    2020-12-30 22:27

    From this question: Maintain Panel Scroll Position On Partial Postback ASP.NET

    I was looking for an answer to this problem for several days, using the typical alternative of MaintainScrollPositionOnPostback and the JavaScript solutions using BeginRequestHandler and EndRequestHandler where in my case I use MasterPage.

    Nothing worked, however I came up with a fairly simple solution using jQuery with BeginRequestHandler and EndRequestHandler using the same @waqas-raja algorithm:

    
    
    
    

    The idea is to capture the position of the Scroll in a global variable each time the user moves the Scroll, in this way it is known which was the last position and when making the postback the EndRequestHandler event is entered and updated with the last position what the user marked

    This worked for me in Firefox and Google Chrome :)

提交回复
热议问题