Not able to set value to Radtext box on Key down event

5 posts, 0 answers
  1. Jidesh Guptha
    Jidesh Guptha avatar
    45 posts
    Member since:
    Apr 2005

    Posted 25 Nov 2010 Link to this post

    Hi,

    I have a scenario where i have to display No. characters entered in a multi line text box on a text box.I have done the following code.
    <telerik:RadTextBox ID="txt_Comment" runat="server" TextMode="MultiLine" Width="50%" Height="50px" onKeyUp="txt_CharacterCount.value=this.value.length" MaxLength="255">
    </telerik:RadTextBox>
      
    <telerik:RadTextBox ID="txt_CharacterCount" ClientIDMode="Static" runat="server" ReadOnly="true" Width="40px">
    </telerik:RadTextBox>

    Its not working for Rad Textbox. but the same is working for aspText box. How do i fix this issue. Pls guide me.
    Jidesh
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Nov 2010 Link to this post

    Hello Jidesh,

    You can attach the OnKeyPress event instead of onKeyUp event like below.

    aspx:
    <telerik:RadTextBox ID="txt_Comment" runat="server" TextMode="MultiLine" Width="50%"
             Height="50px"  MaxLength="255">
             <ClientEvents OnKeyPress="OnKeyPress" />
     </telerik:RadTextBox>

    Javascript:
    function OnKeyPress(sender, args) {
     
         txtbox = sender;
         var count = txtbox.get_textBoxValue().length;//Since the event fired before keypress occurs,add 1 to get exact count 
     }

    Thanks,
    Princy.
  3. Jidesh Guptha
    Jidesh Guptha avatar
    45 posts
    Member since:
    Apr 2005

    Posted 25 Nov 2010 Link to this post

    Hi Princy,

    But this did not suite my requirement because this does not capture the backspace key press and also calculating the new line char.
    can i use keyup event some how?

    thanks
    Jidesh
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Nov 2010 Link to this post

    Hello Jidesh,

    Modify the code as shown below and see whether it helps.

    aspx:
    <telerik:RadTextBox ID="txt_Comment" runat="server" onkeyup="test();" TextMode="MultiLine" Width="50%"
    Height="50px" MaxLength="255">
    </telerik:RadTextBox>

    Clientcode:
    function test()
     {
     
          var textBox1 = $find('<%=txt_Comment.ClientID %>');
          var textBox2 = $find('<%=txt_CharacterCount.ClientID %>');
          var count = textBox1.get_textBoxValue().length;
          textBox2.set_value(count);   
      }

    -Shinu.
  5. Jidesh Guptha
    Jidesh Guptha avatar
    45 posts
    Member since:
    Apr 2005

    Posted 25 Nov 2010 Link to this post

    Hi Shinu,

    This worked but not fully, I followed the below link to solve the issue.
    http://www.telerik.com/community/forums/aspnet-ajax/input/radtextbox-multiline-maxlength-and-enter.aspx

    Thanks for your effort

    Jidesh
Back to Top