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 maintainScrollPositionOnPostBack = "true"
But its not working.
HTML's div with the vertical scrollbar gets back to the original position after PostBack and hence to solve this problem, we need to retain its scroll position value, using JavaScript and then again apply to div after PostBack. This technique helps DIV not to lose its scroll position on PostBack.
During page unload, get the scroll position and store it in local storage. Then during page load, check local storage and set that scroll position.
On long Web pages, this means that the user has to scroll the page back to the last position on the page. When the MaintainScrollPositionOnPostBack property is set to true , the user is instead returned to the last position on the page. You set the MaintainScrollPositionOnPostBack property in the @ Page directive.
I've recently looked for this as well. Came up with a load of Javascript to be inserted until I found the following:
At the top of your .aspx codefile, insert the following:
MaintainScrollPositionOnPostback="true"
so the very first sentence in your .aspx starts
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
This works just fine for me without having to add any other code for keeping scrollbar positions using updatepanels
There are a few ways I have used to set maintainScrollPositionOnPostBack. Have you tried more than one? Can you describe what is triggering the postback and which browsers you have tested? Are you using a master page?
Page.MaintainScrollPositionOnPostBack = true;
in the code behind on page load.<%@ Page MaintainScrollPositionOnPostback="true" %>
<pages maintainScrollPositionOnPostBack="true" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With