2011-09-01 60 views

回答

4

添加以下的jQuery JavaScript中来解决该问题。我不记得我在哪里找到解决方案,但在这里。只需添加目标控件的位置 - $ get('YourDiv_YourPanel')。

<script type="text/javascript"> 
    //Maintain scroll position in given element or control 
    var xInputPanel, yInputPanel; 
    var xProductPanel, yProductPanel; 
    var prm = Sys.WebForms.PageRequestManager.getInstance(); 
    prm.add_beginRequest(BeginRequestHandler); 
    prm.add_endRequest(EndRequestHandler); 
    function BeginRequestHandler(sender, args) { 
     yInputPanel = $get('MainContent_InputPanel').scrollTop; 
     yProductPanel = $get('MainContent_ProductPanel').scrollTop; 
    } 
    function EndRequestHandler(sender, args) { 
     $get('MainContent_InputPanel').scrollTop = yInputPanel; 
     $get('MainContent_ProductPanel').scrollTop = yProductPanel; 
    } 
</script> 
+0

只是为了添加到此解决方案中,请在Content标记内使用此脚本,而不要使用Head标记 – Diogo

0

需要使用此页面指令:

<%@ Page MaintainScrollPositionOnPostback="true" ... %> 
+0

我做到了,但仍然滚动到顶部。我也把它放在更新面板中,但无济于事。我想我可能不得不关闭AutoPostBack并用__doPostBack写一个Javascript函数来击中服务器 – TroyS

+0

你在做重定向吗? –

+0

我不做重新指导。我如何设置事件中的一些标签值。 – TroyS

-1

你有几个选项。您可以在页面指令中将MaintainScrollPositionOnPostBack设置为true,也可以将列表框置于更新面板中并使用AJAX保持滚动位置。

Page指令选项:

<pages maintainScrollPositionOnPostBack="true" /> 

更新面板选项:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
     <asp:ListBox ID="ListBox1" runat="server" ...> 
    </ContentTemplate> 
</asp:UpdatePanel> 
+1

这正是我所拥有的,但似乎并不奏效。 – TroyS

0

我有同样的问题,我想通过更新面板来做到这一点。我相信这是由于列表框正在回发更新,所以更新面板可以帮助我们确保它不会更新。确保列表框是有孩子的条件更新面板内的触发条件设定为“假”:

<asp:UpdatePanel runat="server" ID="updtpnlSearchResults" UpdateMode="Conditional" ChildrenAsTriggers="false"> 

现在把一切需要改变的时候了自己的更新面板内的列表框中选择更改。这样,列表框不会被刷新。