ASP.NET在数据列表和用户控件内的div回发后保持滚动位置

发布于 2024-12-12 16:20:23 字数 903 浏览 2 评论 0原文

我的情况如下所示:我有 x 轴可滚动 div,其中包含显示页数的按钮。该 div 放置在用户控件内的数据列表中,负责在我的网站上显示新闻。

这是这个 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,但我无法弄清楚。

My situation looks like this: I've got x-axis scrollable div that contains buttons with numbers of page displayed. This div is placed in data list inside User Control responsible for displaying news on my site.

This is the code of this div and datalist with page numbers.

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

How to mantain x-axis position of this div after postback? I've tried several tricks, javascript and I can't figure it out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心碎的声音 2024-12-19 16:20:23

有什么理由不使用 UpdatePanel?

Any reason not to use an UpdatePanel?

苍景流年 2024-12-19 16:20:23
<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>
<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文