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

RadTextBox ClientEvents OnKeyPress

2 Answers 893 Views
Input
This is a migrated thread and some comments may be shown as answers.
Evgeniy
Top achievements
Rank 1
Evgeniy asked on 10 Aug 2012, 02:28 PM
Good day.
I try use Client Side of RadTextBox. I need take text from one radtextbox, do changes and set new text into the second radtextbox during user press any key in the first radtextbox.
But behavior is little strange. I use get_value and set_value methods to get and set text from/into radtextbox.
But first, I can't take full text from textbox (last symbol is always missing)
Second, set_value doesn't always update text into radtextbox.
Third, it causes validation error.

Could you please advise how I can make it?

Thanks.

P.S. I can't attach zip file, so I've inserted my code below

<telerik:RadCodeBlock ID="dfg" runat="server">
    <script type="text/javascript">
        function KeyPress(s, e) {
            var v = s.get_value();
            var l = v.replace(',','');
            var ctrl = $find("<%=txtSecond.ClientID %>");
            ctrl.set_value(l);
        }
    </script>
</telerik:RadCodeBlock>
<div>
    Enter some text here <telerik:RadTextBox ID="txtFirst" runat="server" EmptyMessage="Message">
        <ClientEvents OnKeyPress="KeyPress" />
    </telerik:RadTextBox>
    <asp:RequiredFieldValidator ID="wer" runat="server" ControlToValidate="txtFirst" ErrorMessage="*"
        ForeColor="Red" ValidationGroup="gr" SetFocusOnError="true"></asp:RequiredFieldValidator>
    <br /><br />
    Enter some text here <telerik:RadTextBox ID="txtSecond" runat="server" EmptyMessage="Message">
    </telerik:RadTextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtSecond" ErrorMessage="*"
        ForeColor="Red" ValidationGroup="gr" SetFocusOnError="true"></asp:RequiredFieldValidator>
    <br /><br />
     
    <telerik:RadButton ID="btnPostBack" runat="server" Text="Postback" ValidationGroup="gr"></telerik:RadButton>
</div>

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 15 Aug 2012, 12:37 PM
Hello Evgeniy,

Please note that the RadTextBox updated value on the KeyDown or KeyPress event is not available via the standard browser and Javascript methods as it is still not set to the input itself. You could set a small timeout for getting the correct value or use OnValueChanging event.

All the best,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Evgeniy
Top achievements
Rank 1
answered on 16 Aug 2012, 02:47 PM
Thank you for reply.
Using base javascipt code resolve my problem

<telerik:RadCodeBlock ID="dfg" runat="server">
    <script type="text/javascript">
        function KeyPress() {
            var v = document.getElementById('<%=txtFirst.ClientID %>').value;
            var l = v.replace(',','');
            var ctrl = $find("<%=txtSecond.ClientID %>");
            ctrl.set_value(l);
        }
    </script>
</telerik:RadCodeBlock>
<div>
    Enter some text here <telerik:RadTextBox ID="txtFirst" runat="server" EmptyMessage="Message" onkeyup="KeyPress();>
    </telerik:RadTextBox>
    <asp:RequiredFieldValidator ID="wer" runat="server" ControlToValidate="txtFirst" ErrorMessage="*"
        ForeColor="Red" ValidationGroup="gr" SetFocusOnError="true"></asp:RequiredFieldValidator>
    <br /><br />
    Enter some text here <telerik:RadTextBox ID="txtSecond" runat="server" EmptyMessage="Message">
    </telerik:RadTextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtSecond" ErrorMessage="*"
        ForeColor="Red" ValidationGroup="gr" SetFocusOnError="true"></asp:RequiredFieldValidator>
    <br /><br />
      
    <telerik:RadButton ID="btnPostBack" runat="server" Text="Postback" ValidationGroup="gr"></telerik:RadButton>
</div>
Tags
Input
Asked by
Evgeniy
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Evgeniy
Top achievements
Rank 1
Share this question
or