【问题标题】:How to Scroll start with bottom when page is loaded加载页面时如何从底部开始滚动
【发布时间】:2015-02-26 19:07:05
【问题描述】:

您好,我正在使用 asp.net/c# 进行社交网络服务,我在发送消息方面遇到了一些问题。

当我开始发送消息时滚动display like this。当我按下发送消息时,它首先显示旧消息和scroll is top,但我想要更新的消息,这意味着当我加载页面时应该首先显示新消息

我的 aspx 代码

<div style=" overflow-y:auto; height:368px; margin-top: -50px; border-top-style: groove; border-right-style: groove; border-left-style: groove; width: 602px; margin-left: 0px;" >      
              <asp:Repeater runat="server" ID="Repeater1" >
 <ItemTemplate>




     <div style="border-top: thin none #BBCEB3; border-bottom: thin none #BBCEB3; padding: 10px;  width: 548px; margin-top: -10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #fffff0; border-left-color: #BBCEB3; border-right-color: #BBCEB3; border-top-style: groove; border-bottom-style: groove;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <br />
                    <div style="width: 58px; height: 40px">
                    <asp:Image ID="Image2" runat="server" Height="59px" ImageAlign="Top" ImageUrl='<%#Eval("SProfilePic") %> ' Width="55px" />
                        </div>
                    <div style="width: 307px;  margin-left: 65px; margin-top: -60px">
                        <asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#000066"><%#Eval("SenderName") %> </asp:Label>
                    </div>
                    <div id="status" style=" width: 461px; margin-left: 78px; margin-top: 11px;">&nbsp;<asp:Label ID="Label7" runat="server" Font-Italic="False" ForeColor="Black" Font-Size="Medium"><%#Eval("Messages") %> </asp:Label>
                    </div>
                    &nbsp;<div style="margin-left: 400px; background-color: #C0C0C0;">
                        <asp:Label ID="Label11" runat="server"  Text="" Font-Size="Small"><%#Eval("Time") %> </asp:Label>
                    </div>
                </div>




 </ItemTemplate>

【问题讨论】:

    标签: c# jquery css asp.net ajax


    【解决方案1】:

    将服务器控制器放在那里,例如:

    <asp:Button ID="BtnOutside" runat="server" Text="Random" style="margin-left:-999px;" />
    

    然后使用

    Page.SetFocus(Me.BtnOutside.ClientID);
    

    将焦点放在由于负边距而对客户端不可见的那个按钮上。这应该会将滚动条推到底部。

    【讨论】:

    • 谢谢朋友,我应该把这个page.setfocus代码放在哪里?在文件后面的代码上??
    • 是的,放在那里。我猜你的发送按钮确实回发了?因此,当您按下发送按钮并且网站正在回发时,请关注 BtnOutSide
    • 什么是我的关键字?它不退出
    • 试试 Page.SetFocus(BtnOutside);
    • 我认为我们应该关注最新消息,为什么要使用按钮?它不工作
    【解决方案2】:

    把它放在你想要关注的任何地方——你可以使用它

    在同一代码集中多次更改“ID”


    &lt;asp:Button ID="FocusBottom" runat="server" Text="Random" style="margin-left:-999px;"

    在事件中(按钮单击任何内容)放入此。

    Page.SetFocus(FocusBottom);

    把(#######)改成你要调用的“ID”

    【讨论】:

      猜你喜欢
      • 2012-04-29
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多