SoFunction
Updated on 2025-03-07

Automatically scroll to the original location after refreshing the page

After searching online, I summarized three methods:

1. Set the MaintainScrollPositionOnPostback property in Page to true

A>.The page has MaintainScrollPositionOnPostback, the default is false, set to true (page level)

Copy the codeThe code is as follows:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind=""  MaintainScrollPositionOnPostback="true"  Inherits="
ult" %> 

B>. Set the MaintainScrollPositionOnPostback property in the Pages node in the configuration file to true (website level or directory level)

If you modify the website root directory, all pages will be affected. If you modify only files in a certain directory, only pages in this directory will be affected.

Specific methods:

Configure under the <> node:

Copy the codeThe code is as follows:

<pages maintainScrollPositionOnPostBack="true"></pages>

C>. On the page's code page, set the MaintainScrollPositionOnPostback property of page to true through C# or VB code.

Copy the codeThe code is as follows:

= true;

Or write it like this

Copy the codeThe code is as follows:

= true;

2. You can use Jquery to obtain the height of the current position of a certain element, and the specific implementation is as follows

Copy the codeThe code is as follows:

function setPosition() 

var top=$("#element id").offset().top();
     $("html,body").animate({scrollTop:top},1000); 

3. Anchor points can be used, but flexible processing can be used here.

First get the id of the position you need to scroll to. For example, you can set an element (<span name="postion" ></span>, note: it should be in the form), and set it at any position in the form

Copy the codeThe code is as follows:

<a href="#postion" ></a>

Note: Don't have content in the tag a, call it in the place where it is returned.

Copy the codeThe code is as follows:

((), "scroll", "('clickLink').click();", true); 

This method is actually to trigger an event of an element

The above is the entire content of this article, I hope you like it.