如何在嵌套主服务器中的asp.net中异步回发后保持滚动位置? [英] How to Maintain Scroll position after asynchronous postback in asp.net with in the nested master?
问题描述
可能是一个重复的问题我在想什么,但我想要正确的解决方案..
我有一个带嵌套主页的子页面意味着2个母版页继承了另一个......并且在那个子页面中我只有所有用户控件..
所以在我的情况下,我在用户的异步回发后保持子页面的滚动位置控制列表框。
i已经尝试了
MaintainScrollPositionOnPostback =true
with page directive和js code
< script 类型 = text / javascript >
var xPos,yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
函数BeginRequestHandler(sender,args){
xPos = document.getElementById(<% = Panel1.ClientID %> 跨度>)scrollLeft。
yPos = document.getElementById(<% = Panel1.ClientID %> ).scrollTop;
}
函数EndRequestHandler(sender,args){
document.getElementById(<% = Panel1.ClientID %> )。scrollLeft = xPos;
document.getElementById(<% = Panel1.ClientID %> )。 scrollTop = yPos;
}
< / script >
用于面板和div以及更新面板......这些都完全失败,为什么因为如果子页面正在回发意味着相关的主页也贴后备..但我不知道如何保持滚动位置..
尽快帮助我..
谢谢你们
嗨Sharath.Mitte! xPos和yPos是javascript变量,它们在回发时消失。你需要保存在隐藏的字段中。
假设你有一个< asp:hiddenfield id =hidrunat =server/>
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
函数BeginRequestHandler(sender,args){
xPos = document.getElementById("<%= Panel1.ClientID%> ;")。scrollLeft;
yPos = document.getElementById("<%= Panel1.ClientID%>")。scrollTop;
var h = document.getElementById("<%= hid.ClientID%>");
h.value = xPos.toString()+_+ yPos.toString();
}
函数EndRequestHandler(sender,args){
var val = document.getElementById("<%= hid.ClientID% >")。value.split('_');
xPos = parseFloat(val [0]);
yPos = parseFloat(val [1]) ;
document.getElementById("<%= Panel1.ClientID%>")。scrollLeft = xPos;
document.getElementById("<% = Panel1.ClientID%>")。scrollTop = yPos;
}
问候
may its a duplicate question what am asking but i want proper solution..
I have a child page with the nested master means 2 master pages inherit one from another..and in that child page i have all user controls only..
so in my case i have maintain scroll position of child page after async post back of user control list box.
i have tried
MaintainScrollPositionOnPostback="true"
with in page directive and js code
<script type="text/javascript" >
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
xPos = document.getElementById("<%=Panel1.ClientID %>").scrollLeft;
yPos = document.getElementById("<%=Panel1.ClientID %>").scrollTop;
}
function EndRequestHandler(sender, args) {
document.getElementById("<%=Panel1.ClientID %>").scrollLeft = xPos;
document.getElementById("<%=Panel1.ClientID %>").scrollTop = yPos;
}
</script>
for panel and for div and update panel..these all are fails completely, why because if child page is getting post back means the related master pages also post backed..but i don't know how to maintain the scroll position..
try to help me as soon as possible..
thanks guys
Hi Sharath.Mitte! xPos and yPos are javascript variables and they disappear on postback. You'll need to save in a hidden field.
Assuming you have an <asp:hiddenfield id="hid" runat="server"/>
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
xPos = document.getElementById("<%=Panel1.ClientID %>").scrollLeft;
yPos = document.getElementById("<%=Panel1.ClientID %>").scrollTop;
var h = document.getElementById("<%=hid.ClientID %>");
h.value = xPos.toString() + "_" + yPos.toString();
}
function EndRequestHandler(sender, args) {
var val = document.getElementById("<%=hid.ClientID %>").value.split('_');
xPos = parseFloat(val[0]);
yPos = parseFloat(val[1]);
document.getElementById("<%=Panel1.ClientID %>").scrollLeft = xPos;
document.getElementById("<%=Panel1.ClientID %>").scrollTop = yPos;
}
Regards
这篇关于如何在嵌套主服务器中的asp.net中异步回发后保持滚动位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!