[英]How can I set the cursor position at the new line which is after the last line in a multiline textbox using C#?
I have created a chat application, and using using multiline textbox to show the chat messages. 我创建了一个聊天应用程序,并使用多行文本框显示聊天消息。
**Aspx page :**
<asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" Height="163px" Font-Size="0.81em"
Font-Names="Verdana" TextMode="MultiLine"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="refreshTimer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer runat="server" ID="refreshTimer" Interval="2000" Enabled="true"
ontick="refreshTimer_Tick" />
**Behind code :**
protected void refreshTimer_Tick(object sender, EventArgs e)
{
up1.Update();
}
Everything is working fine but after having more messages the TextBox1 refreshes and the last lines get hidden with vertical scrollbar shown, how can I have cursor position at the new line which is after the last line. 一切工作正常,但是在收到更多消息后,TextBox1刷新并且最后一行被显示的垂直滚动条隐藏,如何将光标定位在最后一行之后的新行上。
Thanks in advance....... :) 提前致谢....... :)
I think you can set ClientIDMode="Static" for the textbox as follow: 我认为您可以为文本框设置ClientIDMode =“ Static”,如下所示:
<asp:TextBox ID="TextBox1" runat="server" Height="163px" ClientIDMode="Static" Font-Size="0.81em" Font-Names="Verdana" TextMode="MultiLine"></asp:TextBox>
and after that to put the folling javascript on the page: 然后在页面上放置以下javascript:
<script type="text/javascript">
$(document).ready(function () {
$('#TextBox1').live('change', function () {
$('#TextBox1').scrollTop($('#TextBox1')[0].scrollHeight - $('#TextBox1').height());
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.