<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实现吗?