Maintain scroll position of a div within a page on postback

后端 未结 5 1805
无人共我
无人共我 2020-12-14 22:36

I have a div within an aspx page with overflow set to auto. The contents of the div are dynamically created and consists of a list of link buttons.

5条回答
  •  悲哀的现实
    2020-12-14 23:27

    As Jeff S mentioned one way to handle this situation is using javascript to track the scroll position of the div and each time the page loads reset the scroll position to its previous value.

    Here's some sample code:

    
    
        
    ...........
    ...........
    ...........
    ...........
    ...........
    ...........
    ...........
    ...........
    ...........
    ...........
    ...........
    ...........

    In practice I wouldn't put the javascript directly in the elements but its just an example. You could also store the scroll position in a cookie instead.

提交回复
热议问题