[CLOSED] How to attach/detach listener handlers on the client?

  1. #1

    [CLOSED] How to attach/detach listener handlers on the client?

    Hi,

    I'd like to detach or disable listener handlers on the client so that the same code doesn't execute repeatedly on every event. E.g., as soon as a Save button was made enabled in response to text change in a TextArea, I'd like to disable the KeyPress handler and re-enable it for the TextArea only when the changes are saved or reset.

    Please advise if such a behavior is possible.

    Thanks,

    Vadym
    Last edited by Daniil; Jun 27, 2012 at 5:18 PM. Reason: [CLOSED]
  2. #2
    Hi,

    You could use the removeListener or un methods.
    http://docs.sencha.com/ext-js/3-4/#!...removeListener
    http://docs.sencha.com/ext-js/3-4/#!...able-method-un

    Though it is not too comfortable if you will need to return back that listener.

    Then you could use the following approach.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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>Ext.NET Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:TextArea ID="TextArea1" runat="server" EnableKeyEvents="true">
            <Listeners>
                <KeyDown Handler="if (!this.keyDownLocked) { 
                                        Label1.append(e.getKey());
                                    }" />
            </Listeners>
        </ext:TextArea>
    
        <ext:Label ID="Label1" runat="server" />
    
        <ext:Button runat="server" Text="Lock">
            <Listeners>
                <Click Handler="TextArea1.keyDownLocked = true;" />
            </Listeners>
        </ext:Button>
    
        <ext:Button runat="server" Text="Unlock">
            <Listeners>
                <Click Handler="TextArea1.keyDownLocked = false;" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
  3. #3
    Thanks, this worked for me! Disabling the handlers completely didn't sound like a recommended approach from your suggestion. Do you think there's any significant client performance penalty when a handler is "locked" as opposed to removed completely? While most of the logic escapes execution if keyDownLocked is set to true, the very check for this flag is still done on every KeyDown event.

    Thanks,

    Vadym
  4. #4
    I think there is no any significant difference between the two approaches. You could use the most comfortable for you.
  5. #5
    Thanks Daniil!

    You can mark this question as resolved.

Similar Threads

  1. Replies: 1
    Last Post: Mar 26, 2012, 5:59 PM
  2. [CLOSED] Is there any LoseSelection Grid client listener?
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 03, 2012, 3:31 PM
  3. [CLOSED] Panel.clearContent does not detach events
    By jchau in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 29, 2009, 7:22 AM
  4. [CLOSED] TreeLoader listener client side bug?
    By Justin_Wignall in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 07, 2009, 1:26 PM
  5. [CLOSED] Cannot attach event
    By UGRev in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 07, 2009, 2:03 PM

Tags for this Thread

Posting Permissions