MaintainScrollPositionOnPostback is not working - how to debug?

我只是一个虾纸丫 提交于 2020-01-06 08:42:04

问题


I inherited some web shop project (ASP.NET 3.5, Webforms, Visual Studio 2008 PRO). On one page I have MaintainScrollPositionOnPostback set to true. When shopping cart (user control loaded in master page) is empty, then asp.net is not generating Javascript code required for scroll position. When I add some items to the cart, then everything works fine.

Can you give me any advice how to find part of the code which is responsible for this issue? I don't have an access to the 3rd party profilers.


回答1:


Are you utilizing UpdatePanels in that specific page?

If Yes, following article may give you some direction:

http://basgun.wordpress.com/2008/06/09/maintain-scroll-position-updatepanel-postback/

If No, this one may assist:

Javascript: Maintaining Page Scroll Position
Here is the code from that article:

// function saves scroll position
function fScroll(val)
{
    var hidScroll = document.getElementById('hidScroll');
    hidScroll.value = val.scrollTop;
}

// function moves scroll position to saved value
function fScrollMove(what)
{
    var hidScroll = document.getElementById('hidScroll');
    document.getElementById(what).scrollTop = hidScroll.value;
}
</script>
</head>

<body onload="fScrollMove('div_scroll');" onunload="document.forms(0).submit()";>
<form>
<input type="text" id="hidScroll" name="a">< /br>
<div id="div_scroll" onscroll="fScroll(this);" 
style="overflow:auto;height:100px;width:100px;">

.. VERY LONG TEXT GOES HERE

</div>
</form>
</body>
</html>

Hope one of these links help!



来源:https://stackoverflow.com/questions/4448038/maintainscrollpositiononpostback-is-not-working-how-to-debug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!