从更新面板异步回发后保持滚动位置 [英] Maintain scroll position after async postback from update panel

查看:144
本文介绍了从更新面板异步回发后保持滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些麻烦与asp.net和更新面板。问题是,每一个部分回发时从更新面板时,页面滚动回顶部。在大多数我的网页,这是没有这么大的问题,但在一些网页上可以​​得到相当长。然后,当用户在页面底部,我告诉jQuery的弹出与 RadListView 在里面,用户可以在此列表中选择元素。但点击这个元素会导致局部回传和页面跳转回顶端。

I'm having some troubles with asp.net and update panel. The problem is, that every time partial postback occurs from update panel, page is scrolled back to top. On most of my pages this is not such a big problem, but on some pages can get quite long. Then, when user is on bottom of page, I show jQuery popup with RadListView in it, and user can select element in this list. But clicking on this element causes partial postback and page jumps back to the top.

我已经通过互联网看,找不到任何解决我的问题。课程设置 MaintainScrollPositionOnPostback 不做任何事。

I've looked through internet and could not find any solution to my problem. Of course setting MaintainScrollPositionOnPostback does nothing.

有谁知道什么,可以帮助我解决这个问题?

Does anyone know anything that could help me deal with this problem?

干杯, PAKO

推荐答案

有一个小解决此,我已经在ERP很久以前使用。不知道这是最好的解决方案,但它的工作原理。

There is a little workaround for this, that I've used in an ERP long time ago. Not sure if it's the best solution, but it works.

我不知道,如果你使用自定义页面类或默认的 System.Web.UI.Page ,但是,我会尽力向你解释你是怎么做的,然后你发现,你可以在你的环境中实现它的最好办法,好吗?

I don't know if you use a custom Page class or the default System.Web.UI.Page one, but, I'll try to explain to you how you do it, and then you find out the best way you can implement it in your environment, alright?

您将创建一个 HiddenField ,例如,ID为hfScrollPosition。

You'll create a HiddenField, for example, with the ID "hfScrollPosition".

然后,你会成为一个JavaScript事件: document.onscroll 或类似的东西,而事件中,你会更新的隐藏字段来获得当前滚动位置。例如: 的document.getElementById(hfScrollPosition)值= document.documentElement.scrollTop;

Then, you'll make a javascript event: document.onscroll or something like that, and inside the event you'll update the hidden field to get the current scroll position. For example: document.getElementById("hfScrollPosition").value = document.documentElement.scrollTop;

这样做,你将有一个ASP.NET控件dinamically更新其价值,照在身上滚动位置。所以,当你的页面一定的控制,使回发,你可以把下面的JavaScript code在Page_Load事件:

Doing that, you'll have an ASP.NET control updating its value dinamically, according to the body scroll position. So, when some control in your page makes a postback, you can put the following javascript code in your Page_Load event:

document.documentElement.scrollTop =的document.getElementById(hfScrollPosition)值。

所以,每次你的页面得到一个回发,身体滚动位置将被正确更新。

So, everytime your page gets a postback, the body scroll position will be correctly updated.

修改:我做了一个小提琴模拟它: https://jsfiddle.net/j26fpgzo/

EDIT: I've made a fiddle to simulate it: https://jsfiddle.net/j26fpgzo/

这篇关于从更新面板异步回发后保持滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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