Asp. NET page refreshes and automatically scrolls to its original location

Source: Internet
Author: User

After searching the web, we summarize three ways:

1. Set the MaintainScrollPositionOnPostBack property in page to True

A&GT: The page has MaintainScrollPositionOnPostBack, default is False, set to True (page level)
<%@ 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 under the root of the site, all pages are affected, and only the Web. config file under a directory affects only the pages in that directory

Specific measures:

Configure under the <system.web> node:

<pages maintainscrollpositiononpostback="true"

C>. On the code page of the page, set the page's MaintainScrollPositionOnPostBack property to True by using C # or VB codes

true;

or write like this

 This true;


2. You can use jquery to achieve the following function SetPosition () {var top=$ ("#元素id") by getting the height of the current position of an element. Offset (). Top ();  $ ("Html,body"). Animate ({scrolltop:top},1000); } 3. You can use anchor points, but here you can use flexible processing to first get the ID of the position to scroll to, for example, you can set an element (<span name= "postion" id= "postion" &GT;&LT;/SPAN&GT; note: To be in a form), In addition, set <a href= "#postion" id= "Clicklink" in any position of the form ></a> Note: Do not have content in a tag, call in place of callback
Page.ClientScript.RegisterStartupScript (this"scroll""  document.getElementById (' Clicklink '). Click (); " true);  

This method is actually the event that triggers an element

Asp. NET page refreshes and automatically scrolls to its original location

Related Article

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.