每次刷新后,文本框将滚动回到顶部位置 [英] After every refresh the textbox scrolls back to top position

查看:102
本文介绍了每次刷新后,文本框将滚动回到顶部位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上附加了一个聊天应用程序,用户可以从文本框中输入数据,并且用户可以使用多行模式的文本框查看另一侧的回复.但是,问题是我在updatePanel中添加了多行文本框使用计时器定期刷新.这里出现了问题,每次刷新后,文本框都会滚动回到顶部位置.用户无法查看最近收到的消息.

I have a chat application attached to my website where the user enters data from a textbox and user can view the replies from the other side using textbox with multiline mode.But,The Problem is I had added the Multiline textbox inside an updatePanel with the Timer to refresh periodically.The problem arises here,After every refresh the textbox scrolls back to top position.The user cant view the recently recieved messages.
can,Any one suggests the way to overcome the problem?

推荐答案

要保持滚动位置,有两种选择:
1.尝试MaintainScrollPosition页面属性.参考: MSDN:Page.MaintainScrollPositionOnPostBack属性 [ ^ ]

2.您可以在onchange事件触发之前跟踪客户端的滚动位置.页面刷新后,将滚动位置恢复到上次存储的位置.参考:文章的一部分提供了实现方法 [ ^ ]
To maintain scroll position, 2 options:
1. try MaintainScrollPosition page attribute. Refer: MSDN: Page.MaintainScrollPositionOnPostBack Property [^]
OR
2. you can keep track of the scroll position on client side before the onchange event fires. Restore the scroll position back to what you stored last time after the page refresh. Refer: Part of the article provides way to do it[^]


您可以通过使用名为ScrollToCaret的函数来完成此操作.您需要先将插入符号的位置设置为文本框的末尾,然后才能滚动至该位置.操作方法如下:
You can do this by making use of a function called ScrollToCaret. You need to first set the caret position to the end of the text box, then you can scroll to it. Here''s how to do it:
//move the caret to the end of the text
textBox.SelectionStart = textBox.TextLength;
//scroll to the caret
textBox.ScrollToCaret();
//Sets the cursor
textBox.Focus();



我相信SelectionStart仅可用于 System.Windows.Forms.TextBox [^ ] .将此属性集用于 System.Web.UI.WebControls.TextBox [^ ].



I believe SelectionStart is only available for System.Windows.Forms.TextBox[^]. Use this set of properties for System.Web.UI.WebControls.TextBox[^].


你好

hello

TextBox1.Select(TextBox1.TextLength, 1)
TextBox1.ScrollToCaret()
TextBox1.Focus()



这将选择文本框中的最后一个字符.如果要选择整个最后一行,则只需将Select方法中的第二个参数调整为=最后一行的长度.



如果调用AppendText将新文本添加到TextBox,则它将自动滚动到文本的末尾.



That will select the last character in the text box. If you want to select the entire last row you can just adjust the 2nd parameter in the Select method to be = the length of the last line.

or

If you call AppendText to add new text to the TextBox then it will automatically scroll to the end of the text.


这篇关于每次刷新后,文本框将滚动回到顶部位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆