如何保养后,页面回发的asp.net页面滚动位置 [英] How to maintain page scroll position after a page postback in asp.net

查看:98
本文介绍了如何保养后,页面回发的asp.net页面滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <meta http-equiv="refresh" content="4" />   
 <script type="text/javascript">

    var xPos1, yPos1;

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoading(pageLoadingHandler);
    prm.add_pageLoaded(pageLoaded);
    function pageLoaded(sender, args) {

        $get('<%=Panel_Users.ClientID %>').scrollLeft = xPos1;
        $get('<%=Panel_Users.ClientID %>').scrollTop = yPos1;
    }
    function pageLoadingHandler(sender, args) {
        xPos1 = $get('<%=Panel_Users.ClientID %>').scrollLeft
        yPos1 = $get('<%=Panel_Users.ClientID %>').scrollTop;
    }
    </script>
</asp:Content>

不行的,我要去哪里错了。

Doesn't work, where am I going wrong

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"  />    

<div style="height: 504px; width: 941px;">
                 <asp:Panel runat="server" ID="Panel_Users" ScrollBars="Auto" Style="z-index: 1; left: 748px;
                     top: 621px; position: absolute; height: 250px; width: 287px">
                     <asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel1" runat="server">
                         <ContentTemplate>
                             <asp:GridView ID="Grid_UserTable" runat="server" Style="z-index: 1; left: 2px; top: 5px;
                                 position: absolute; height: 152px; width: 243px" BorderColor="#666666" AutoGenerateColumns="False"
                                 OnRowDataBound="MyGrid_RowDataBound">
                                 <Columns>
                                     <asp:TemplateField HeaderText="Status">
                                         <ItemTemplate>
                                             <asp:Image ID="Status" runat="server" />
                                         </ItemTemplate>
                                     </asp:TemplateField>
                                     <asp:BoundField DataField="TimeReceived" HeaderText="TimeReceived" InsertVisible="False"
                                         ReadOnly="True" SortExpression="TimeReceived" />
                                     <asp:BoundField DataField="TimeRead" HeaderText="TimeRead" SortExpression="TimeRead" />
                                     <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                                 </Columns>
                             </asp:GridView>
                         </ContentTemplate>
                     </asp:UpdatePanel>
                 </asp:Panel>
             </div>

我试图使页面停留在相同的位置时,页面每5秒后刷新的页面去顶。我试着页MaintainScrollPositionOnPostback =真。它没有工作,我尝试使用Ajax,但不知道如何使用它。有人可以帮助我如何使用Ajax做到这一点。

I am trying to make the page stay at the same position when the page refreshes after every 5 seconds and the page goes to top. I tried Page MaintainScrollPositionOnPostback="true" . It didn't work, I tried using Ajax but have no idea how to use it. Can someone help me how to do it with Ajax.

推荐答案

该MaintainScrollPositionOnPostback只适用于IE浏览器。要做到这一点,你既可以推出自己的客户端脚本,或者使用在您的网页/表单不同部分的锚链接。

The MaintainScrollPositionOnPostback only works in IE. To do this you can either roll your own client script or use anchor links on different sections of your page/form.

类似的问题在这里:

<一个href="http://stackoverflow.com/questions/4448038/maintainscrollpositiononpostback-is-not-working-how-to-debug">MaintainScrollPositionOnPostback不工作 - 如何调试

<一个href="http://stackoverflow.com/questions/4899461/maintainscrollpositiononpostback-not-working-with-javascript-dopostback">MaintainScrollPositionOnPostback不工作的javascript:__ doPostBack

<一个href="http://stackoverflow.com/questions/2084229/maintainscrollpositiononpostback-true-does-not-work-globally-after-setting-in-w">maintainScrollPositionOnPostback="true"没有在web.config中设置后在全球开展工作,但工作在页面级别,我该怎么办?

这篇关于如何保养后,页面回发的asp.net页面滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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