This is a migrated thread and some comments may be shown as answers.

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

4 Answers 226 Views
Input
This is a migrated thread and some comments may be shown as answers.
Jidesh Guptha
Top achievements
Rank 1
Jidesh Guptha asked on 25 Nov 2010, 09:41 AM
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

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Nov 2010, 10:31 AM
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.
0
Jidesh Guptha
Top achievements
Rank 1
answered on 25 Nov 2010, 11:38 AM
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
0
Shinu
Top achievements
Rank 2
answered on 25 Nov 2010, 12:33 PM
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.
0
Jidesh Guptha
Top achievements
Rank 1
answered on 25 Nov 2010, 12:51 PM
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
Tags
Input
Asked by
Jidesh Guptha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jidesh Guptha
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or