Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Ajax
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
Edited 27-Jul-12 19:31pm
v2
Comments
Kenneth Haugland at 28-Jul-12 1:38am
   
Dont the multiline textboxes have scroll into view ?
Rate this: bad
good
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 [^]
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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hello
 
            TextBox1.Select(TextBox1.TextLength, 1)
            TextBox1.ScrollToCaret()
            TextBox1.Focus()
 
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.
  Permalink  
v2
Comments
Nandakishorerao at 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
good
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
        textBox.ScrollToCaret();
        //Sets the cursor
        textBox.Focus();
 
I believe SelectionStart is only available for System.Windows.Forms.TextBox[^]. Use this set of properties for System.Web.UI.WebControls.TextBox[^].
  Permalink  
v3
Comments
_Amy at 28-Jul-12 1:53am
   
Check my updated answer.
Nandakishorerao at 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 windows...app...

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



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 29 Jul 2012
Copyright © CodeProject, 1999-2014
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