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

OnKeyPressed Q2 2012 Issue

12 Answers 160 Views
Input
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 19 Jun 2012, 02:50 PM
I recently upgraded to the Q2 2012 controls and immediately started having an issue with my search button.  User can enter a name to search.  Pressing ENTER will begin the search.  I initiate the click event when the ENTER key (keyCode=13) is pressed.  In the previous release this worked perfectly.  Now I must put in a delay because there is no value returned from the get_value() on the first attempt.  Can this be explained??  I have included code and jpg images showing the alert get_value() in sequence.  I keyed in "bee" into the text box and pressed ENTER.  The jpgs show the results.

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

Sort by
0
John
Top achievements
Rank 1
answered on 19 Jun 2012, 03:04 PM
Followup: Had to put in a delay and remove the set_cancel(true) to get this to work.  Still would appreciate you looking into this issue and providing a better fix with an explanation to give me a warm & fuzzy.
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);
 }
}
0
John
Top achievements
Rank 1
answered on 21 Jun 2012, 04:59 PM
I've created a support ticket regarding since no answer within 24hrs.  Found an additional issue with same bug.  It fires a RadButton "OnClick" event too.  Including quick code that was sent to support.  Hopefully answers arriving soon.

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>


0
Tony
Top achievements
Rank 2
answered on 21 Jun 2012, 09:46 PM
I'm having the same issue with a password field.  When i hit enter it does not post back. I have to hit it twice for it to work which is really annoying.  This login form has been working for the last 3 years. Upgrading to the newest version broke my login form

0
John
Top achievements
Rank 1
answered on 21 Jun 2012, 10:25 PM
http://www.telerik.com/community/forums/aspnet-ajax/input/problem-with-defaultbutton-in-q2-2012.aspx
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.
0
John
Top achievements
Rank 1
answered on 22 Jun 2012, 11:38 AM
For everyone else to see the support ticket response.  My app has worked fine for over a year and now I find out it worked because of a bug in telerik control.  Doesn't make my day...nor is the response from support correct.  According to this response get_value() should supply some text content onKeyPress, it does not.  If they had bothered to use my simple code example this would have been seen. I have asked for them to review....once again.  I was able to create a complicated mash of code to work around this issue.  I used the KeyPress event to set a boolean flag and set focus to another control which caused the OnBlur event to fire.  In the onBlur I check the boolean for ENTER being pressed and get_value()...which surprise is now the value I expected.  Again complicated work around but until telerik recognizes this as a bug I had to do something.

************************************************************************************************************************************************
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
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
John
Top achievements
Rank 1
answered on 22 Jun 2012, 03:31 PM
Got an answer that I can work with to resolve.  My fix will be to do a "set_value(.get_textBoxValue())" in the onKeyPress event.  This will handle issues client-side and server-side.

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
0
Makoto
Top achievements
Rank 1
answered on 06 Jul 2012, 08:58 PM
Thanks John. I had the exact same issue and your workaround works great.
0
Fawad
Top achievements
Rank 1
answered on 16 Jul 2012, 10:02 AM
Thanks John, that did it. 

Regards.
0
David
Top achievements
Rank 1
answered on 02 Aug 2012, 06:42 PM
I was able to recover the current key being pressed as we also had this problem 

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
}
0
peter
Top achievements
Rank 1
answered on 07 Aug 2012, 02:12 PM
Hi!

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?
0
John
Top achievements
Rank 1
answered on 07 Aug 2012, 05:20 PM
Peter, My understanding from telerik support when I found the issue was that this behavior was a "fix" to another bug. Meaning that this is not considered a bug and this is now considered the correct behavior. If I am incorrect, telerik can correct me regarding. My fix to their fix is still working fine, weird that I must set one property to another, but that is the way that it is. From responses to this thread we are not alone in our grief. Maybe telerik will take note, until that time I suggest apply my client side logic to correct the issue. Telerik can you add more information on this issue. Several of us are listening. John
0
Vasil
Telerik team
answered on 10 Aug 2012, 01:23 PM
Hello David,

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
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.
Tags
Input
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Tony
Top achievements
Rank 2
Makoto
Top achievements
Rank 1
Fawad
Top achievements
Rank 1
David
Top achievements
Rank 1
peter
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or