保持网页提交后股利滚动位置(ASP.NET) [英] Maintain scroller position on Div after page postback (ASP.NET)

查看:122
本文介绍了保持网页提交后股利滚动位置(ASP.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div这样:

<div style="overflow-y: scroll; height: 260px">

我包含了几百个记录,并让我选择一个项目来填充它下面的FormView控件。

I contains a few hundred records and allows me to select an item to populate a formview control below it.

问题是,当页面帖回,滚动条位置返回到div的顶部。我想尝试并保持其位置,使选定的记录仍是可见的。

The problem is that when the page posts-back, the scroller position goes back to the top of the div. I want to try and maintain its position so that the selected record is still visible.

任何想法?

推荐答案

将是这样的:

 <asp:HiddenField id="hdnScrollPos" runat="server"/> in your aspx.

于是,一些JavaScript这样的:

Then, some javascript like:

var hdnScroll = document.getElementById(<%=hdnScrollPos.ClientID%>);
var bigDiv = document.getElementById('bigDiv');
bigDiv.onscroll = function() {
     hdnScroll.value = bigDiv.scrollTop;
}

window.onload = function () { 
    bigDiv.scrollTop = hdnScroll.value;
}

这篇关于保持网页提交后股利滚动位置(ASP.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆