Click here to Skip to main content
13,048,805 members (85,545 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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?
Posted 27-Jul-12 19:20pm
Updated 27-Jul-12 19:31pm
Kenneth Haugland 28-Jul-12 1:38am
Dont the multiline textboxes have scroll into view ?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

To maintain scroll position, 2 options:
1. try MaintainScrollPosition page attribute. Refer: MSDN: Page.MaintainScrollPositionOnPostBack Property [^]
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[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


TextBox1.Select(TextBox1.TextLength, 1)

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.


If you call AppendText to add new text to the TextBox then it will automatically scroll to the end of the text.
Nandakishorerao 28-Jul-12 1:47am
NileshBhai..Thank u for the response..But,I had already Used this tech..But its not working..The error i got is

System.Web.UI.WebControls.TextBox' does not contain a definition for 'SelectionStart' and no extension method 'SelectionStart' accepting a first argument of type 'System.Web.UI.WebControls.TextBox' could be found (are you missing a using directive or an assembly reference?)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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
//Sets the cursor

I believe SelectionStart is only available for System.Windows.Forms.TextBox[^]. Use this set of properties for System.Web.UI.WebControls.TextBox[^].
_Amy 28-Jul-12 1:53am
Check my updated answer.
Nandakishorerao 28-Jul-12 2:34am
_Amy..Thank u..for reply..but SelectionStart is not a function which can be used in the web application..It belongs to

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 29 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100