在没有更新面板的情况下在PostBack上维护DIV滚动位置 [英] Maintaining DIV Scroll Position on PostBack without Update Panel
本文介绍了在没有更新面板的情况下在PostBack上维护DIV滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不使用更新面板的情况下在Postback上维护DIV滚动位置。
谢谢和问候
Deepak
解决方案
看一下这篇文章: Ajax更新后的页面控件的JavaScript访问(通过更新面板) [ ^ ]
更新:
很抱歉不读''不更新面板''
你可以试试,
1.Page.MaintainScrollPositionOnPostBack = true;
2.您可以在回发之前跟踪滚动位置,然后在页面加载时,在页面加载时使用javascript你可以设置回滚动。
你好,
首先,我建议使用:
Page.MaintainScrollPositionOnPo stBack = true;
在你的PageLoad活动中保持整页的页面位置。
现在,对于div问题。我在这里找到了一个很好的解决方案:
http:// radio.javaranch.com/pascarello/2005/07/18/1121709316718.html [ ^ ]
我稍微改了一下,以便使用hiddenfield而不是cookie。以下是结果。
< script type =text / javascript>
window.onload = function(){
var h = document.getElementById(<%= keep.ClientID%>);
document.getElementById(divTest)。scrollTop = h.value;
alert(h.value);
}
函数SetDivPosition(){
var intY = document.getElementById(divTest)。scrollTop;
var h = document.getElementById(<%= keep.ClientID%>);
h.value = intY;
}
< / script>
以下是您要维护的div的起始标记。
<divönscroll=SetDivPosition()id =divTest>
< / div>
注意:
- divTest是的名称你希望维护的div
- keep是我使用的隐藏字段的名称
使用IE 8,Firefox 4测试希望它有所帮助!
hosamkamel /存档/ 2007/09/07 /维持-滚动位置后回传,在-ASP净2-0.aspx> http://weblogs.asp.net/hosamkamel/archive/2007/09 /07/maintain-scroll-position-after-postbacks-in-asp-net-2-0.aspx [ ^ ]
http://weblogs.asp。 net / andrewfrederick / archive / 2008/03/04 / maintain-scroll-position-after-asynchronous-postback.aspx [ ^ ]
http://scottonwriting.net/sowblog/archive/2006/12/ 14 / 163224.aspx [ ^ ]
How do i maintain DIV scroll Position on Postback without using Update Panel.
Thanks and Regards
Deepak
解决方案
Have a look at this article: JavaScript Access to Page Controls after Ajax Update (via Update Panel)[^]
UPDATE:
Sorry for not reading ''not update panel''
You can try,
1.Page.MaintainScrollPositionOnPostBack = true;
2. You can track the scroll position before the postback and then when the page is loading, on page load using javascript you can set back the scroll.
Hello,
Firstly, I would suggest using:
Page.MaintainScrollPositionOnPostBack = true;
in your PageLoad event to maintain page position for your whole page.
Now, for the div question. I found a nice solution to your question here:
http://radio.javaranch.com/pascarello/2005/07/18/1121709316718.html[^]
I changed it a bit so to work with hiddenfield and not cookie. Below is the result.
<script type="text/javascript"> window.onload = function () { var h = document.getElementById("<%=keep.ClientID%>"); document.getElementById("divTest").scrollTop = h.value; alert(h.value); } function SetDivPosition(){ var intY = document.getElementById("divTest").scrollTop; var h = document.getElementById("<%=keep.ClientID%>"); h.value = intY; } </script>
Below is the starting tag of the div you want to maintain.
<div önscroll="SetDivPosition()" id="divTest"> </div>
Notes:
- "divTest" is the name of the div you wish to maintain
- "keep" is the name of the hidden field I used
Tested with IE 8, Firefox 4 and Chrome 12.
Hope it helps!
http://weblogs.asp.net/hosamkamel/archive/2007/09/07/maintain-scroll-position-after-postbacks-in-asp-net-2-0.aspx[^]
http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx[^]
http://scottonwriting.net/sowblog/archive/2006/12/14/163224.aspx[^]
这篇关于在没有更新面板的情况下在PostBack上维护DIV滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文