gpt4 book ai didi

javascript - 如何在 asp.net 中的页面回发后保持页面滚动位置

转载 作者:数据小太阳 更新时间:2023-10-29 03:59:16 25 4
gpt4 key购买 nike

<分区>

<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>

不起作用,我哪里错了

    <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 秒刷新一次并且页面转到顶部时,我试图使页面保持在同一位置。我试过 Page MaintainScrollPositionOnPostback="true"。它没有用,我尝试使用 Ajax 但不知道如何使用它。有人可以帮助我如何使用 Ajax 做到这一点。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com