Ajax更新面板滚动条问题

发布于 2024-08-09 09:00:06 字数 197 浏览 2 评论 0原文

我有一个更新面板,其中有数据列表。

此更新面板每 1 秒触发一次,以从数据库检索数据。

我已将此更新面板保留在启用垂直滚动的 div 标签内。

但是当我获取新数据时,滚动条不会自动调整!

我尝试过维护滚动选项,但它不起作用。

updatepanel 触发后是否有任何选项可以将滚动条保持在原始位置?

I have one update panel inside which I have datalist.

This update panel triggers every 1 second to retrieve the data from db.

I have kept this update panel inside a vertical scroll enabled div tag.

But when I get new data, the scroll bar is not adjusting automatically !!!

I have tried maintainscrollback option but its not working.

Is there any option to maintain the scroll bar to it original position after the updatepanel triggers?

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

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

发布评论

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

评论(3

飞烟轻若梦 2024-08-16 09:00:06

请尝试这个:

<script>
  var prm = Sys.WebForms.PageRequestManager.getInstance();
  prm.add_beginRequest(function(){
     window.dTop = document.getElementById('divIdHere').scrollTop;
  });

  prm.add_endRequest(function(){
       setTimeout(function(){
         document.getElementById('divIdHere').scrollTop = window.dTop;
      },100);
  });
</script>

Please try this:

<script>
  var prm = Sys.WebForms.PageRequestManager.getInstance();
  prm.add_beginRequest(function(){
     window.dTop = document.getElementById('divIdHere').scrollTop;
  });

  prm.add_endRequest(function(){
       setTimeout(function(){
         document.getElementById('divIdHere').scrollTop = window.dTop;
      },100);
  });
</script>
小红帽 2024-08-16 09:00:06

这是我更喜欢避免使用 JavaScript 的地方,它需要每次刷新/更新时调整滚动位置...

我想你一定已经设计了如下所示的页面

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional/Always">
    <ContentTemplate>
        <div style="height: 400px/300px; overflow-y:scroll;"> 
            <asp:DataList ID="DataList1" runat="server">
                ....
            </asp:DataList>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

将其更改为这样的内容应该可以解决滚动问题

<div style="height: 400px/300px; overflow-y:scroll;"> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional/Always">
        <ContentTemplate>
                <asp:DataList ID="DataList1" runat="server">
                    ....
                </asp:DataList>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

Here is what I prefer to avoid JavaScript, which needs to adjust scroll position each and every refresh/update...

I guess you must have designed page like below

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional/Always">
    <ContentTemplate>
        <div style="height: 400px/300px; overflow-y:scroll;"> 
            <asp:DataList ID="DataList1" runat="server">
                ....
            </asp:DataList>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

Change it to some thing like this should take care of scroll issue

<div style="height: 400px/300px; overflow-y:scroll;"> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional/Always">
        <ContentTemplate>
                <asp:DataList ID="DataList1" runat="server">
                    ....
                </asp:DataList>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
仅一夜美梦 2024-08-16 09:00:06

我正在处理的网页遇到了同样的问题,其中面板更新后滚动条不起作用。将 UpdatePanel 标签放在 div 标签内解决了我的问题。

因此,将以下内容更改

<UpdatePanel>
    <ContentTemplate>
         <div>
        </div>
    </ContentTemplate>
</UpdatePanel>

为,

<div>
<UpdatePanel>
    <ContentTemplate>
    </ContentTemplate>
</UpdatePanel>
</div>

I was facing the same problem for a webpage I was working on wherein after the panel update the scroll bar didnt work. Putting the UpdatePanel tag inside the div tag solved my issue.

So, change the below

<UpdatePanel>
    <ContentTemplate>
         <div>
        </div>
    </ContentTemplate>
</UpdatePanel>

to,

<div>
<UpdatePanel>
    <ContentTemplate>
    </ContentTemplate>
</UpdatePanel>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文