Auto-scroll to bottom of multiline RadTextBox

6 posts, 1 answers
  1. Chad Strawinski
    Chad Strawinski avatar
    4 posts
    Member since:
    Apr 2010

    Posted 15 Apr 2010 Link to this post

    I'm trying to figure out a way to continuously add lines to a multi-line RadTextBox that automatically shows the last line added instead of staying at the top of the textbox. My goal is to basically display a log of events, so if there's another way I'm open to ideas. A multi-line textbox was just the first idea that came to my mind.

    I've tried setting SelectionOnFocus to CaretToEnd and continuously setting the focus to the textbox, but all it seems to do is keep the caret placed on bottom of the textbox without scrolling down. Any help would be appreciated!

    Thanks,
    Chad

  2. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 20 Apr 2010 Link to this post

    Hi Chad,

    Please, refer to the online example below, which handles the desired functionality. Give it a try and let me know if it work as expected:
    Multi-line TextBox

    I hope this helps.

    Sincerely yours,
    Pavlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Chad Strawinski
    Chad Strawinski avatar
    4 posts
    Member since:
    Apr 2010

    Posted 20 Apr 2010 Link to this post

    Pavilina,

    The difference between the example and what I'm trying to do is that in the example, you're manually typing into the textbox and what I need to do is programmatically add text to the textbox while keeping the last line added visible. There seems to be a difference in behavior when adding text to the textbox programmatically versus typing into the textbox manually.

    Here's a simple example of what I'm talking about:

    TestPage.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="TestWebApp.TestPage" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head runat="server">  
        <title></title>  
    </head> 
    <body> 
        <form id="form1" runat="server">  
        <asp:ScriptManager runat="server" ID="ScriptManager1" /> 
        <div> 
            <asp:Timer runat="server" ID="timer1" Interval="500" OnTick="timer1_Tick" /> 
            <telerik:RadTextBox ID="rtbMultiLine" runat="server" TextMode="MultiLine">  
            </telerik:RadTextBox> 
        </div> 
        </form> 
    </body> 
    </html> 
     

    TestPage.aspx.cs
    using System;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
     
    namespace TestWebApp  
    {  
        public partial class TestPage : System.Web.UI.Page  
        {  
            protected void Page_Load(object sender, EventArgs e)  
            {  
     
            }  
     
            protected void timer1_Tick(object sender, EventArgs e)  
            {  
                rtbMultiLine.Text += "Tick\n";  
            }  
        }  

    When I run this, once the textbox is filled, it keeps going past the end of the textbox but does not keep the last added line visible. I've tried various ways of trying to accomplish this with javascript but I haven't been able to get any examples I've seen online to work (I think mostly because every example I see deals with static text and not constantly updating like this). Let me know if you need any more from me in trying to figure this out. I've already spent a day on this without luck =/

    Thanks,
    Chad
  4. Answer
    Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 23 Apr 2010 Link to this post

    Hello Chad,

    Please, find attached a simple working application which handles the desired functionality. Give it a try and let me know if it works as expected.

    I hope this helps.

    Best wishes,
    Pavlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Chad Strawinski
    Chad Strawinski avatar
    4 posts
    Member since:
    Apr 2010

    Posted 23 Apr 2010 Link to this post

    Pavlina,

    That worked perfectly! Thank you so much. I'll try to incorporate this into the project I'm working on. Hopefully the textbox being inside an update panel won't cause me problems :)

    Thanks,
    Chad
  6. Chad Strawinski
    Chad Strawinski avatar
    4 posts
    Member since:
    Apr 2010

    Posted 26 Apr 2010 Link to this post

    One minor modification I would like to point out for anyone who may use this in the future, is in the Javascript portion of the code the IE conditional causes script errors in IE8, so I changed 'if ($telerik.isIE)' to 'if ($telerik.isIE && !$telerik.isIE8)'. The else part works in IE8 without problems.

    Thanks,
    Chad

Back to Top