我的情况是这样的:我有一个x轴可滚动的div,其中包含显示页码的按钮。这个div被放置在User Control中的数据列表中,负责在我的网站上显示新闻。
这是这个div和带有页码的数据列表的代码。
<div style="width:430px; overflow:auto; overflow-y:hidden; -ms-overflow-y:hidden; vertical-align:top; position:relative; top:-1px; ">
<asp:DataList ID="dlPaging" runat="server" OnItemCommand="dlPaging_ItemCommand" RepeatDirection="Horizontal"
OnItemDataBound="dlPaging_ItemDataBound">
<ItemTemplate>
<asp:Button ID="lnkbtnPaging" class="pagebutton" runat="server" CommandArgument='<%# Eval("PageIndex") %>'
CommandName="lnkbtnPaging" Text='<%# Eval("PageText") %>' CausesValidation="False" />
</ItemTemplate>
</asp:DataList>
</div>
如何在回发后保持这个div的x轴位置?我试过几个技巧,javascript,我不能弄清楚。
有理由不使用UpdatePanel吗?
<div id="divDtPaging" runat="server" visible="true" style="width: 50%; overflow: scroll; text-align: center">
<asp:DataList runat="server" ID="dtPaging" OnItemCommand="dtPaging_ItemCommand"
OnItemDataBound="dtPaging_ItemDataBound" RepeatDirection="Horizontal"
SeparatorStyle-Wrap="true" Style="height: auto">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkbtnPaging" Text="PageText" CommandArgument="PageIndex" Style="padding-right: 5px">
</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</div>
<asp:HiddenField id="hdnScrollPos" runat="server"/>
<script type="text/javascript">
function BeginRequestHandler(sender, args)
{
document.getElementById('<%=hdnScrollPos.ClientID %>').value = document.getElementById('<%=divDtPaging.ClientID %>').scrollLeft;
}
function EndRequestHandler(sender, args) {
document.getElementById('<%=divDtPaging.ClientID %>').scrollLeft = document.getElementById('<%=hdnScrollPos.ClientID %>').value;
}
if (window.Sys && Sys.WebForms && Sys.WebForms.PageRequestManager) {
var prm = Sys.WebForms.PageRequestManager.getInstance()
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
}
</script>