how to retain the browser scroll position after an

2019-05-04 19:50发布

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.

3条回答
够拽才男人
2楼-- · 2019-05-04 20:27

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>
查看更多
叛逆
4楼-- · 2019-05-04 20:41

Did you tried declaratively setting MaintainScrollPositionOnPostBack property on your page ,

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs"
    Inherits="test" MaintainScrollPositionOnPostback="true" %>
查看更多
登录 后发表回答