I am putting in a slight delay to correct for the moment. I would really like an explanation because now I worry I'm going to find other issues.
Thanks
John
<telerik:RadTextBox ID="txtSearch" runat="server" EmptyMessage="Enter First or Last Name..."
Width="145px" Skin="WebBlue">
<PasswordStrengthSettings IndicatorWidth="100px" />
<ClientEvents OnKeyPress="onKeyPressed" />
</telerik:RadTextBox>
function onKeyPressed(sender, args) {
var search = $find("<%= btnSearch.ClientID %>");
//ENTER key pressed on Search
if (args.get_keyCode() == 13) {
alert('Value=' + sender.get_value() + ' Time=' + Date());
alert('Value=' + sender.get_value() + ' Time=' + Date());
search.click();
args.set_cancel(true);
}
}
12 Answers, 1 is accepted

Thanks
function onKeyPressed(sender, args) {
var search = $find("<%= btnSearch.ClientID %>");
//ENTER key pressed on Search
if (args.get_keyCode() == 13) {
setTimeout(function () {
search.click();
}, 100);
// args.set_cancel(true);
}
}

Key something into the RadInput and press ENTER. Note that the value in the first alert is blank, then note at the end the click event fires for the button.....weird.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestJWT.aspx.cs" Inherits="MConsole.TestJWT" %>
<!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">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function onKeyPress(sender, args) {
//ENTER key pressed on Search
if (args.get_keyCode() == 13) {
alert('Value1=' + sender.get_value() + ' Time=' + Date());
alert('Value2=' + sender.get_value() + ' Time=' + Date());
// args.set_cancel(true);
}
}
function onButtonClick() {
alert("Button Clicked");
}
</script>
</telerik:RadCodeBlock>
<div>
<telerik:RadTextBox ID="RadTextBox1" runat="server" Label="InputTextBox">
<ClientEvents OnKeyPress="onKeyPress" />
</telerik:RadTextBox>
<telerik:RadButton ID="RadButton1" runat="server"
onclientclicked="onButtonClick" Text="RadButton">
</telerik:RadButton>
</div>
</form>
</body>
</html>


Check the above thread, it may hold the answer. I've asked telerik to confirm in my support ticket, haven't heard anything yet. I'm trying to be patient.

************************************************************************************************************************************************
Hello John,
On KeyPress the value is actually not changed yet. The value is changed on blur or after pressing enter key.
On this event it was possible to use the get_value before, but it actually returned wrong value as a side effect of a bug.
For example if you type "123" , on the latest keypress ('3'), the get_value() would return you "12". However this was not correct, because the submit value would be 123.
All the best,
Vasil
the Telerik team

I'm including the support response below so that others can resolve if they have this issue. 2-part response because I wanted to resolve how to get this same value on the server-side since ".text" would be blank during the onKeyPress event.
*****************************************************************************************************
Hello John,
You can always use the .get_textBoxValue() to get the value in the visible input element.
Kind regards,
Vasil
the Telerik team
*****************************************************************************************************
Hello John,
1. get_value returns the current value of the control, and on keyPress the value is still not updated.
2. get_textBoxValue() can be used to get the visible value in the input. It returns the current value.
3. After the textbox has blured client side, or a set_value() is used, or enter key is pressed, then the .Text property server side will hold correct value.
4. DisplayText property is to be used to preset text that to be displayed client side after page renders.
Please note that on point (2) the value in the input does not contain the pressed key. You could replicate the same behaviour using normal asp:TextBox, or <input> element and handle the keypress DOM event. On this event the value does not contain last pressed key.
Kind regards,
Vasil
the Telerik team


Regards.

function RadTextBox_OnKeyPress(sender, e) {
var currentKey = e.get_keyCode();
var oldText = sender.get_textBoxValue();
var newText = oldText + String.fromCharCode(currentKey);
sender.set_value(newText);
sender.set_textBoxValue(oldText);
//some code
}

I'm having the same problem in this release. Then i have upgraded to version Q2 731 hotfix but the problem persists.
In older versions it works fine. When will telerik fix this bug?

Note that if the user actually paste a text using Ctrl+V and the caret is in the middle of the text this line will not be correct:
var newText = oldText + String.fromCharCode(currentKey);
The same will happen if you type when caret is not in the end or you are using backspace.
You can handle onkeyup event of the html input, and too the logic there.
<
script
>
function keyuphandler(element, event)
{
var input = $find(element.id);
input.set_value(element.value);
}
</
script
>
<
telerik:RadTextBox
onkeyup
=
"keyuphandler(this,event)"
....>
Greetings,
Vasil
the Telerik team