After searching the web, three ways are summarized:
1. Set the MaintainScrollPositionOnPostBack property in page to True
A>: MaintainScrollPositionOnPostBack in page, default is False, set to True (page level)
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= true "codebehind=" Default.aspx.cs "maintainscrollpositiononpostback=" True "inherits=" Default.defa
Ult "%>
B> Set the MaintainScrollPositionOnPostBack property in the pages node in the Web.config configuration file to True (site-level or directory-level)
If you modify web.config in the root of the Web site, all pages will be affected, but only the Web.config files in a directory affect the pages in this directory.
Specific measures:
Under the <system.web> node configuration:
Copy Code code as follows:
<pages maintainscrollpositiononpostback= "true" ></pages>
C> On the code page of the page, set the page's MaintainScrollPositionOnPostBack property to True by using C # or VB code
Copy Code code as follows:
Page.maintainscrollpositiononpostback = true;
or write like this
Copy Code code as follows:
This. MaintainScrollPositionOnPostBack = true;
2. You can use jquery to get the height of the current position of an element, which is implemented as follows
Copy Code code as follows:
function SetPosition ()
{
var top=$ ("#元素id"). Offset (). Top ();
$ ("Html,body"). Animate ({scrolltop:top},1000);
}
3. You can use anchor points, but here you can use flexible handling
First get the ID of the location you want to scroll to, for example, you can set an element (<span name= "postion" id= "postion" ></SPAN> note: to be in form), and set at any point in the form
Copy Code code as follows:
<a href= "#postion" id= "Clicklink" ></a>
Note: A label does not have content in the return of the place to call
Copy Code code as follows:
Page.ClientScript.RegisterStartupScript (this. GetType (), "scroll", "document.getElementById (' Clicklink ')." Click (); ", true);
This method is actually the event that triggers an element
The above mentioned is the entire content of this article, I hope you can enjoy.