8 个解决方案
#1
//使用cookie ,js:
<script id=clientEventHandlersJS language=javascript>
<!--
window.onload =function() {
if(getcookie(height)!=null)
document.body.scrollTop=getcookie(height);
}
window.onunload =function () {
setcookie("height",document.body.scrollTop);
}
function getcookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
function setcookie(sName, sValue)
{
date = new Date();
date.setTime(date.getTime()+60000); //1 minute
document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}
//-->
</script>
#2
Page.MaintainScrollPositionOnPostBack = true;
#3
正好我这几天做的东西遇到这个问题,不知道你指的滚动条是body的还是div的,这里给你举个div的例子:
大概的思路就是刷新前用一个隐藏域记录当前滚动条位置,当刷新时读取这个记录
//刷新时滚动条保留位置
function ScrollToSelectNode()
{
document.getElementById("left").scrollTop = "<%=ScrollValue%>";
}
function bindData()
{
document.getElementById("divScrollValue").value = document.getElementById("left").scrollTop;
}
<body onload="ScrollToSelectNode()">
<form id="Form1" runat="server" onsubmit="bindData()">
<input runat="server" id="divScrollValue" type="hidden" value="" />
public static string ScrollValue = string.Empty;//滚动条位置
protected void Page_Load(object sender, EventArgs e)
{
ScrollValue = divScrollValue.Value;
}
大概的思路就是刷新前用一个隐藏域记录当前滚动条位置,当刷新时读取这个记录
#4
Page.MaintainScrollPositionOnPostBack = true;是对页面的滚动条,对DIV的滚动条无效的。我看看先luqc1985的。谢谢啊
#5
lnit728,我没看明白是滚动条滚动后,怎么记录它的位置。我的Q522797821,方便加上,我做了一个小测试工程。谢谢
#6
给你个实例吧啊,记得把分给我啊,呵呵
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="treeview.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
//滚动到选择节点
function bindData(){
document.getElementById("divScrollValue").value = document.getElementById("divScroll").scrollTop;
}
function ScrollToSelectNode()
{
document.getElementById("divScroll").scrollTop = "<%=ScrollValue%>"
}
</script>
</head>
<body onload="ScrollToSelectNode()">
<form id="form1" onsubmit="bindData()" runat="server">
<input runat="server" id="divScrollValue" type="hidden" value="" />
<div id="divScroll" runat="server" style="float: left; text-align: left; width: 220px;
height: 420px; overflow: scroll; border: #003278 1px solid;">
<asp:TreeView ID="TreeView1" AutoGenerateDataBindings="false" runat="server" ShowExpandCollapse="False"
BorderStyle="None" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" NodeIndent="10">
<SelectedNodeStyle Font-Bold="True" Font-Underline="True" />
<NodeStyle HorizontalPadding="2px" NodeSpacing="2px" VerticalPadding="2px" BorderStyle="None" />
<RootNodeStyle Font-Size="10.5pt" />
<LeafNodeStyle Font-Size="9pt" />
</asp:TreeView>
</div>
<div id="d"></div>
</form>
</body>
</html>
using System;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public static string ScrollValue = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TreeView1.Nodes.Clear();
for (int i = 0; i < 50; i++)
{
TreeNode node = new TreeNode();
node.Text = "树节点" + i;
TreeView1.Nodes.Add(node);
}
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
ScrollValue = divScrollValue.Value;
}
}
#7
需要的是IFrame里面的层位置固定....
#8
正找呢!谢了
#1
//使用cookie ,js:
<script id=clientEventHandlersJS language=javascript>
<!--
window.onload =function() {
if(getcookie(height)!=null)
document.body.scrollTop=getcookie(height);
}
window.onunload =function () {
setcookie("height",document.body.scrollTop);
}
function getcookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
function setcookie(sName, sValue)
{
date = new Date();
date.setTime(date.getTime()+60000); //1 minute
document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}
//-->
</script>
#2
Page.MaintainScrollPositionOnPostBack = true;
#3
正好我这几天做的东西遇到这个问题,不知道你指的滚动条是body的还是div的,这里给你举个div的例子:
大概的思路就是刷新前用一个隐藏域记录当前滚动条位置,当刷新时读取这个记录
//刷新时滚动条保留位置
function ScrollToSelectNode()
{
document.getElementById("left").scrollTop = "<%=ScrollValue%>";
}
function bindData()
{
document.getElementById("divScrollValue").value = document.getElementById("left").scrollTop;
}
<body onload="ScrollToSelectNode()">
<form id="Form1" runat="server" onsubmit="bindData()">
<input runat="server" id="divScrollValue" type="hidden" value="" />
public static string ScrollValue = string.Empty;//滚动条位置
protected void Page_Load(object sender, EventArgs e)
{
ScrollValue = divScrollValue.Value;
}
大概的思路就是刷新前用一个隐藏域记录当前滚动条位置,当刷新时读取这个记录
#4
Page.MaintainScrollPositionOnPostBack = true;是对页面的滚动条,对DIV的滚动条无效的。我看看先luqc1985的。谢谢啊
#5
lnit728,我没看明白是滚动条滚动后,怎么记录它的位置。我的Q522797821,方便加上,我做了一个小测试工程。谢谢
#6
给你个实例吧啊,记得把分给我啊,呵呵
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="treeview.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
//滚动到选择节点
function bindData(){
document.getElementById("divScrollValue").value = document.getElementById("divScroll").scrollTop;
}
function ScrollToSelectNode()
{
document.getElementById("divScroll").scrollTop = "<%=ScrollValue%>"
}
</script>
</head>
<body onload="ScrollToSelectNode()">
<form id="form1" onsubmit="bindData()" runat="server">
<input runat="server" id="divScrollValue" type="hidden" value="" />
<div id="divScroll" runat="server" style="float: left; text-align: left; width: 220px;
height: 420px; overflow: scroll; border: #003278 1px solid;">
<asp:TreeView ID="TreeView1" AutoGenerateDataBindings="false" runat="server" ShowExpandCollapse="False"
BorderStyle="None" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" NodeIndent="10">
<SelectedNodeStyle Font-Bold="True" Font-Underline="True" />
<NodeStyle HorizontalPadding="2px" NodeSpacing="2px" VerticalPadding="2px" BorderStyle="None" />
<RootNodeStyle Font-Size="10.5pt" />
<LeafNodeStyle Font-Size="9pt" />
</asp:TreeView>
</div>
<div id="d"></div>
</form>
</body>
</html>
using System;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public static string ScrollValue = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TreeView1.Nodes.Clear();
for (int i = 0; i < 50; i++)
{
TreeNode node = new TreeNode();
node.Text = "树节点" + i;
TreeView1.Nodes.Add(node);
}
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
ScrollValue = divScrollValue.Value;
}
}
#7
需要的是IFrame里面的层位置固定....
#8
正找呢!谢了