[CLOSED] KeyDown Event Not Firing

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] KeyDown Event Not Firing

    I am using version v 0.8.1 of Coolite and have found this strange behaviour which I have a workaround for.

    The html below just shows 2 controls on a page, the 2nd control txtWhy is hidden.

    <script type="text/javascript">
    function CheckKeyDown(keypressed) {
    var isEnter = keypressed.getKey() == keypressed.ENTER;
    return isEnter;
    }
    </script>
    
    <ext:Panel runat="server" ID="ww" Border="false">
    <Body>
    <ext:FormLayout ID="FormLayout2" runat="server" LabelAlign="Left" LabelWidth="120">
    <ext:Anchor>
    <ext:NumberField ID="txtInput" runat="server" FieldLabel="Input" AllowDecimals="false"
    EnableKeyEvents="true" Width="400">
    <AjaxEvents>
    <KeyDown OnEvent="txtInput_KeyDown" Before="return CheckKeyDown(params[1]);">
    </KeyDown>
    </AjaxEvents>
    </ext:NumberField>
    </ext:Anchor>
    <ext:Anchor>
    <ext:TextField ID="txtWhy" Hidden="true" runat="server" >
    </ext:TextField>
    </ext:Anchor>
    <ext:Anchor>
    <ext:TextArea ID="txtOP" runat="server" Width="400" Height="400" FieldLabel="Output">
    </ext:TextArea>
    </ext:Anchor>
    </ext:FormLayout>
    </Body>
    </ext:Panel>
    The code behind is simple as well:
    Sub txtInput_KeyDown(ByVal sender As Object, ByVal e As AjaxEventArgs)
    If Not txtInput.Text = Nothing Then
    txtOP.Text = txtOP.Text &amp; vbNewLine &amp; txtInput.Text
    txtInput.Clear()
    txtInput.Focus()
    End If
    End Sub
    This, when run will build up the contents of what you type in the top control in the bottom control, easy.

    Now, comment out the hidden control and try again.

    The Keydown event does not seem to fire...
    Is this something I have done on my code, or a bug?

  2. #2

    RE: [CLOSED] KeyDown Event Not Firing

    I have found something else strange with this event, related somewhat to another posting:
    http://forums.ext.net/showthread.php...hlight=barcode although the implementation is different.

    I am using a barcode reader which is effectively a keyboard loop that reads a barcode and then sends a carriage return (Enter) to the comtrol that has the focus, in my example the txtInput control.

    I have tested the barcode reader in notepad and it provides the correct response.

    For example (from my barcode reader, which I surrounded by quotes)
    '9781857230765
    '

    Can you think of any reason why the KeyDown event of the previous posting would fire twice, but only update the txtOP.text once?

    Both events seem to originate from the textfield as it is the sender in both events.

    Am I doing something to fire the KeyDown event twice, or is this a fault?
  3. #3

    RE: [CLOSED] KeyDown Event Not Firing

    Hi,

    I tested under 0.8.1 and all works correctly. Which browser do you use?
    Here is my test case
    <%@ Page Language="C#" AutoEventWireup="true" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!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>
        
        <script runat="server">
            protected void txtInput_KeyDown(object sender, AjaxEventArgs e)
            {
                if (!string.IsNullOrEmpty(txtInput.Text)){
                    txtOP.Text = txtOP.Text + "\n" + txtInput.Text;
                    txtInput.Clear();
                    txtInput.Focus();
                }
            }
        </script>
        
        <script type="text/javascript">
            function CheckKeyDown(keypressed) {
                var isEnter = keypressed.getKey() == keypressed.ENTER;
                return isEnter;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ScriptManager ID="ScriptManager1" runat="server" />
    
        
    
        <ext:Panel runat="server" ID="ww" Border="false">
            <Body>
                <ext:FormLayout ID="FormLayout2" runat="server" LabelAlign="Left" LabelWidth="120">
                    <ext:Anchor>
                        <ext:NumberField ID="txtInput" runat="server" FieldLabel="Input" AllowDecimals="false"
                            EnableKeyEvents="true" Width="400">
                            <AjaxEvents>
                                <KeyDown OnEvent="txtInput_KeyDown" Before="return CheckKeyDown(params[1]);">
                                </KeyDown>
                            </AjaxEvents>
                        </ext:NumberField>
                    </ext:Anchor>
                    <ext:Anchor>
                        <ext:TextField ID="txtWhy" runat="server">
                        </ext:TextField>
                    </ext:Anchor>
                    <ext:Anchor>
                        <ext:TextArea ID="txtOP" runat="server" Width="400" Height="400" FieldLabel="Output">
                        </ext:TextArea>
                    </ext:Anchor>
                </ext:FormLayout>
            </Body>
        </ext:Panel>
        </form>
    </body>
    </html>
  4. #4

    RE: [CLOSED] KeyDown Event Not Firing

    I agree that your code sample works, however, if I comment out the control 'txtWhy' and its anchor, it does not work.

    <ext:Anchor>
    
    
    <ext:NumberField ID="txtInput" runat="server" FieldLabel="Input" AllowDecimals="false"
    
    
    EnableKeyEvents="true" Width="400">
    
    
    <AjaxEvents>
    
    
    <KeyDown OnEvent="txtInput_KeyDown" Before="return CheckKeyDown(params[1]);">
    
    
    </KeyDown>
    
    
    </AjaxEvents>
    
    
    </ext:NumberField>
    
    
    </ext:Anchor>
    
    
    <%-- <ext:Anchor>
    
    
    <ext:TextField ID="txtWhy" runat="server">
    
    
    </ext:TextField>
    
    
    </ext:Anchor>--%>
    
    
    <ext:Anchor>
    
    
    <ext:TextArea ID="txtOP" runat="server" Width="400" Height="400" FieldLabel="Output">
    
    
    </ext:TextArea>
    
    
    </ext:Anchor>
    Do you have any idea why I might be getting 2 KeyDown events firing as in my second post?
  5. #5

    RE: [CLOSED] KeyDown Event Not Firing

    Hi,

    I tested witout that textfield and it works correctly also. May be your browser makes postback on Enter?
    Try the folloiwng Before handler for KeyDown event
    Before="var res = CheckKeyDown(params[1]); if(res){e.stopEvent();}return res;"

    Unfortunatelly, I have no idea why KeyDow fires twice after barcode scanning. Do you mean server side handler or client side? What if to use KeyPress instead KeyDown? Does it the same behaviour?
  6. #6

    RE: [CLOSED] KeyDown Event Not Firing

    The KeyDown and KeyPress events (tried them both) are server-side events called from an AjaxEvent of my numberfield control.

    Both events have the same behaviour. Both events that fire are PostBack's.

    I have also noticed the same behaviour from a swipe card reader which also acts as a keyboard loop.

    It is like the text entry occurs too fast for the event to handle.

    I thought of a workaround that stores the time of the last enter key press and ignores key presses that are within the last few milliseconds..... unfortunatley, this did not work as both events fire, seemingly, at the same time.

    I am using IE7.
  7. #7

    RE: [CLOSED] KeyDown Event Not Firing

    Hi,

    Did you try my Before handler? It should prevent postback
  8. #8

    RE: [CLOSED] KeyDown Event Not Firing

    Embarassingly, I am not using v0.8.1 of Cooloite, it is v0.8.2.30060 . Hopefully this will make this easier to track down.

    I tried the before handler and it threw up an error.

    Line: 193 Error: Member not found. When I debug this it shows me an error with the following line.




    return this;},stopEvent:function(){if(this.browserEvent){ if(this.browserEvent.type=='mousedown'){Ext.EventM anager.stoppedMouseDownEvent.fire(this);}

    Where the this.browerEvent is 'Member Not Found.'

  9. #9

    RE: [CLOSED] KeyDown Event Not Firing

    Hi,

    I am still cannot reproduce the problem. Can you create test project, zip it and post?
  10. #10

    RE: [CLOSED] KeyDown Event Not Firing

    Here is thew project you requested.

    It contains 4 web forms.

    2 pages with the extra control commented out.
    NoExtraControl.aspx - with your 'Before' event
    NoExtraControl2.aspx - with the original 'Before' event

    2 pages with the extra control in.
    WithExtraControl.aspx - with your 'Before' event
    WithExtraControl2.aspx - with the original 'Before' event

    Regards,
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] KeyDown and KeyPress Event
    By rosua in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 04, 2012, 11:43 AM
  2. [CLOSED] BeforeClientInit event not firing
    By jchau in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Apr 04, 2011, 7:07 PM
  3. Replies: 2
    Last Post: Nov 01, 2010, 5:29 PM
  4. [CLOSED] KeyPress,KeyDown,KeyUp Events not firing
    By randy85253 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 23, 2009, 5:08 PM
  5. MultiHeader keydown event
    By methode in forum Open Discussions
    Replies: 5
    Last Post: Mar 04, 2009, 4:29 PM

Posting Permissions