Asp. NET Refresh page automatically scroll to the original location method Summary _ Practical Tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.