[CLOSED] Event firing several times.

  1. #1

    [CLOSED] Event firing several times.

    Hi,

    #Vladimir helped me solve this problem below, but found an error.

    http://forums.ext.net/showthread.php...t-multselect#4

    I tried to solve but could not.

    Test steps:

    1-Press ctrl and select one item.
    2-Press ctrl and select two items.
    3-Press ctrl and select one item.

    The SelectionShow method is called several times.

    My Ext.NET version is 1.3

    Change the method ShowSelection for that. So you can better see what happen.

     [DirectMethod]
            public void ShowSelection()
            {
                X.Msg.Notify("Selection", "You selected " + Select1.SelectedItems.Count + " items").Show();
            }
    Any suggestion?
    Last edited by Daniil; Jan 07, 2013 at 8:03 AM. Reason: [CLOSED]
  2. #2
    Hi @stoque,

    It needs to detach the keyup listener.

    Example
    <%@ Page Language="C#" %>
      
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        [DirectMethod]
        public void ShowSelection()
        {
            X.Msg.Notify("Selection", "You selected " + this.MultiSelect1.SelectedItems.Count + " items").Show();
        }
    </script>
    
    <!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>  
      
        <script type="text/javascript">
            var onKeyUp = function (event, el, options) {
                if (event.getKey() == event.CTRL){
                    options.field.listening = false;
                    Ext.net.DirectMethods.ShowSelection();
                    Ext.getDoc().un("keyup", onKeyUp, null);
                }    
            };
    
            var onItemClick = function (field, event) {   
                if (event.ctrlKey) {
                    if (!field.listening) {
                        field.listening = true;
                        Ext.getDoc().on("keyup", onKeyUp, null, { field: field });
                    }
                }            
                else {
                    Ext.net.DirectMethods.ShowSelection();
                }
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
              
            <ext:MultiSelect 
                ID="MultiSelect1" 
                runat="server" 
                Width="300" 
                Height="250" 
                KeepSelectionOnClick="WithCtrlKey">
                <Items>
                    <ext:ListItem Text="Item 1" Value="1" />
                    <ext:ListItem Text="Item 2" Value="2" />
                    <ext:ListItem Text="Item 3" Value="3" />
                    <ext:ListItem Text="Item 4" Value="4" />
                    <ext:ListItem Text="Item 5" Value="5" />
                </Items>              
                <Listeners>
                    <Click Fn="onItemClick" />
                </Listeners>          
            </ext:MultiSelect>      
        </form>
    </body>
    </html>
  3. #3
    Hi Daniil.

    Works fine.

    I tried detach the keyup listener, but not worked. =/

    Thanks for your exemple.

    Please, mark as solved !!
  4. #4
    Quote Originally Posted by stoque View Post
    I tried detach the keyup listener, but not worked. =/
    To detach you should pass to the un or removeListener method the event name, the function and the scope, the same ones which were passed to the on or addListener method.

Similar Threads

  1. [CLOSED] MenuItem OnClick event not firing
    By Fahd in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 16, 2012, 5:50 AM
  2. [CLOSED] Click event launched several times
    By jeybonnet in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 23, 2011, 8:31 AM
  3. [CLOSED] BeforeClientInit event not firing
    By jchau in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Apr 04, 2011, 7:07 PM
  4. [CLOSED] Button event firing twice?
    By geodan in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Aug 18, 2010, 7:03 PM
  5. Replies: 4
    Last Post: Jan 28, 2009, 12:28 PM

Tags for this Thread

Posting Permissions