轻松解决页面回传后页面滚动到顶端
页面回传后页面滚动到顶端,造成这一问题的原因是页面回传,其实等于载入一次页面,新载入的页面会定点到页面的顶端。这一特点会造成很差的用户使用感受,如何解决这一问题呢,我们可以借用隐藏的ViewState机制保存当前页面滚动的位置,在页面回传后调用。
<%@ Page language="c#" Codebehind="Test_THIN.aspx.cs" AutoEventWireup="false" Inherits="EIM.web.Test_THIN" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Test_THIN</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function savescroll()
{
var hid = document.getElementById("hid");
hid.value = document.body.scrollTop;
}
function getscroll()
{
var hid = document.getElementById("hid");
//hid.value = document.body.scrollTop;
document.body.scrollTop = hid.value;
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" οnlοad="getscroll()" οnscrοll="savescroll()">
<form id="Test_THIN" method="post" runat="server" οnsubmit="savescroll()">
<INPUT style="Z-INDEX: 101; LEFT: 216px; POSITION: absolute; TOP: 127px" type="hidden" id="hid" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 37px; POSITION: absolute; TOP: 1529px" runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>