How to keep the scroll position of a browser after an event occurs

When I click on any button, my page loads and the position of the page changes.

the first page scrolls down, and then from top to top by moving it down.

How can I save the scroll position also after refreshing the page each time I click on an event.

I tried

Page.MaintainScrollPositionOnPostBack = true;

On my page it loads, but it doesnโ€™t work.

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

I have one aspx page in which I call 5 web users.

Please help me..

How can I save the scroll position also after refreshing the page each time I click on an event.

+4
source share
3 answers

I used the update panel as well as this script and its work is good 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> 
0
source

You tried to declaratively set the MaintainScrollPositionOnPostBack property on your page,

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

All Articles