Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在刷新页面时使用asp.net定时器控件将div标记中的向下滚动条设置为垂直滚动条_C#_Javascript_Asp.net_Html_Scrollbar - Fatal编程技术网

C# 如何在刷新页面时使用asp.net定时器控件将div标记中的向下滚动条设置为垂直滚动条

C# 如何在刷新页面时使用asp.net定时器控件将div标记中的向下滚动条设置为垂直滚动条,c#,javascript,asp.net,html,scrollbar,C#,Javascript,Asp.net,Html,Scrollbar,我正在使用asp.net开发一个聊天应用程序,在该应用程序中使用div标记和indiv标记添加asp.netLiteral消息框和一个计时器控件,现在我的问题是页面何时刷新或单击按钮(任何时间)div滚动条始终位于顶部,但我希望它位于底部,如何调整我的代码 <div id="divMessages" style="background-color: White; border-color:Black;border-width:1px;border-style:solid;height:30

我正在使用asp.net开发一个聊天应用程序,在该应用程序中使用
div
标记和in
div
标记添加asp.net
Literal
消息框和一个计时器控件,现在我的问题是页面何时刷新或单击按钮(任何时间)
div
滚动条始终位于顶部,但我希望它位于底部,如何调整我的代码

<div id="divMessages" style="background-color: White; border-color:Black;border-width:1px;border-style:solid;height:300px;width:592px;overflow-y:scroll; font-size: 11px; padding: 4px 4px 4px 4px;" onresize="SetScrollPosition()">
  <asp:Literal Id="litMessages" runat="server" />
</div>
<asp:TextBox Id="txtMessage" onkeyup="ReplaceChars()" onfocus="SetToEnd(this)" runat="server" MaxLength="100" Width="500px" ClientIDMode="Static" />
<asp:Button Id="btnSend" runat="server" Text="Send" OnClientClick="SetScrollPosition()" OnClick="BtnSend_Click" ClientIDMode="Static"/>
请给我一些建议


我检查了它是否与更新面板一起工作,但我也有更新面板和计时器控件,我需要使用这些控件来维护底部的div滚动条。请给我任何建议…………

我可能有一个简单的解决方案,但我不确定您是否想要

在传统方式中,我们可以为url设置锚定,并在访问此页面时让页面滚动到特定位置。类似于此:

因此,您可以编写一些js来控制这个锚

<div id="divMessages" onresize="SetScrollPosition()">
    <asp:Literal Id="litMessages" runat="server" />
</div>
<div id="msg-local" />//add new element is to auto scroll to here.

function SetScrollPosition()
{
     ......
     //set the url with anchor
     window.location.hash = "go-msg-local"; 
     //set this value can disable browser auto scroll
 }
检查此代码


var xPos,yPos;
var prm=Sys.WebForms.PageRequestManager.getInstance();
函数BeginRequestHandler(发送方,参数){
如果($get(“”)!=null){
xPos=$get(“”).scrollLeft;
yPos=$get(“”).scrollTop;
}
}
函数EndRequestHandler(发送方,参数){
如果($get(“”)!=null){
xPos=$get(“”)。scrollLeft=xPos;
yPos=$get('').scrollTop=yPos;
}
}
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);

检查下面的链接!!!我看到了这个例子,请检查它是否正常,java脚本出错,请给我详细说明,这对更新面板中包含的用户控件非常有用。谢谢
<div id="divMessages" onresize="SetScrollPosition()">
    <asp:Literal Id="litMessages" runat="server" />
</div>
<div id="msg-local" />//add new element is to auto scroll to here.

function SetScrollPosition()
{
     ......
     //set the url with anchor
     window.location.hash = "go-msg-local"; 
     //set this value can disable browser auto scroll
 }
 function page_load {
    if (window.location.hash) {
      window.location.hash = "msg-local"; 
    }
 }
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"
            ScriptMode="Release" />
        <script type="text/javascript">
            var xPos, yPos;
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            function BeginRequestHandler(sender, args) {
                if ($get('<%=divMessages.ClientID%>') != null) {
                    xPos = $get('<%=divMessages.ClientID%>').scrollLeft;
                    yPos = $get('<%=divMessages.ClientID%>').scrollTop;
                }
            }
            function EndRequestHandler(sender, args) {
                if ($get('<%=divMessages.ClientID%>') != null) {
                    xPos = $get('<%=divMessages.ClientID%>').scrollLeft = xPos;
                    yPos = $get('<%=divMessages.ClientID%>').scrollTop = yPos;
                }
            }
            prm.add_beginRequest(BeginRequestHandler);
            prm.add_endRequest(EndRequestHandler);
        </script>