在网上搜索之后总结了三种方式:

1.设置Page中的MaintainScrollPositionOnPostback属性为true

  A>.页面里有MaintainScrollPositionOnPostback,默认是false,设为true即可(页面级)
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"  MaintainScrollPositionOnPostback="true"  Inherits="Default.Defa
ult" %>

  B>.设置web.config配置文件中的Pages节点中的MaintainScrollPositionOnPostback属性为true(网站级或目录级)

    如果修改网站根目录下的web.config则所有的页面均会受影响,若只修改某个目录下的web.config文件则只影响这个目录中的页面

   具体办法:

  在<system.web>节点下配置:

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

  C>.在页面的code页面,通过C#或VB代码设置page的MaintainScrollPositionOnPostback属性为true

Page.MaintainScrollPositionOnPostBack = true;

或这样写

this.MaintainScrollPositionOnPostBack = true;
2.可以使用Jquery,通过获取某个元素当前位置的高度,具体实现如下
function setPosition()  
{  
     var top=$("#元素id").offset().top();  
     $("html,body").animate({scrollTop:top},1000);  
}  
 
3.可以使用锚点,但这里可使用灵活处理
首先获取需要滚动到的位置的id,如,可以设置一个元素(<span name="postion" id="postion"></span>,注:要在form里),另外在form的任意位置设置
<a href="#postion" id="clickLink"></a>
注:a标签里不要有内容,在回传的地方调用
Page.ClientScript.RegisterStartupScript(this.GetType(), "scroll", "document.getElementById('clickLink').click();", true);  
这种方法其实就是触发某个元素的事件

最新文章

  1. Java学习笔记(七)&mdash;&mdash;对象
  2. http://blog.sina.com.cn/s/blog_5bd6b4510101585x.html
  3. Oracle常用监控SQL
  4. ahjesus如何在windows下制作适用于mac的u盘启动盘
  5. android studio annotation 配置过程
  6. Spring day01
  7. git学习笔记12-标签管理-版本
  8. 铁人系列(2)LA2218
  9. poj2528(线段树+离散化)Mayor&#39;s posters
  10. 【转】Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
  11. ubuntu 14.04 apt-get 方式安装oracle JDK
  12. mac版sublime text2包管理器安装步骤
  13. 类型“System.Data.Objects.DataClasses.EntityObject”在未被引用的程序集中定义。
  14. 消除警告&quot;property access result unused - getters should not be used for side effects&quot;
  15. Carbondata源码系列(一)文件生成过程
  16. Python面向对象:杂七杂八的知识点
  17. Mysql中设置指定IP的特定用户及特定权限
  18. &lt;转载&gt;ford-fulkerson算法
  19. java子类继承关系
  20. Web重温系列(二):SQLite+EF6实现本地化存储

热门文章

  1. Android开源代码分享
  2. Android之输入框光标和Hint的位置
  3. IBM powerVM VIOS
  4. eclipse 手动/自动安装插件
  5. 3D全景!这么牛!!
  6. 【干货分享】Google 的设计准则,素材和资源
  7. [数据库]sql之行顺序
  8. 学习android开发笔记
  9. jQuery源码分析之=&gt;jQuery的定义
  10. 自定义JSTL标签和函数库