how to retain the browser scroll position after any event gets fire

笑着哭i 提交于 2019-12-22 09:12:07

问题


When I am clicking on any button my page is re loading and page position is getting change.

first page is scrolling bottom then going on top again its moving to down side.

How could I retain the scroll position same after page refresh on any event click.

I tried

Page.MaintainScrollPositionOnPostBack = true;

on my page load but its not working.

I used ajax updatepanel after using it my browser is getting stuck, and performance is very slow.

I have one aspx page, in that i am calling 5 web user control.

Please any one help me..

How could I retain the scroll position same after page refresh on any event click.


回答1:


Did you tried declaratively setting MaintainScrollPositionOnPostBack property on your page ,

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs"
    Inherits="test" MaintainScrollPositionOnPostback="true" %>



回答2:


Have look into this article Maintain Scroll Position after Asynchronous Postback

and check this thread Reset scroll position after Async postback - ASP.NET




回答3:


I used update panel as well as this script and its working well for me..

 <script>
    var xPos, yPos;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);
    function BeginRequestHandler(sender, args) {
        xPos = document.getElementById("<%=Panel4.ClientID %>").scrollLeft;
        yPos = document.getElementById("<%=Panel4.ClientID %>").scrollTop;
    }
    function EndRequestHandler(sender, args) {
        document.getElementById("<%=Panel4.ClientID %>").scrollLeft = xPos;
        document.getElementById("<%=Panel4.ClientID %>").scrollTop = yPos;
    }
 </script>


来源:https://stackoverflow.com/questions/6109505/how-to-retain-the-browser-scroll-position-after-any-event-gets-fire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!