Call both DirectEvent and Listener for the same event

  1. #1

    Call both DirectEvent and Listener for the same event

    Hello,

    Is it possible to define a handler of DirectEvent and Listener for the same event? For example I have this button, in which I define handlers for the click event at the DirectEvent and Listener. Here's the piece of code

                            <ext:Button ID="ButtonItemSave" runat="server" Text="Save" Icon="Disk">
                                <DirectEvents>
                                    <Click OnEvent="ButtonItemSave_Click"></Click>
                                </DirectEvents>
                                <Listeners>
                                    <Click Handler="#{ButtonItemSave}.setDisabled(true)" />
                                </Listeners>
                            </ext:Button>
    On the code, when the button is clicked, I want to call server code ButtonItemSave_Click and also run the client script to disable the button. Is this possible? if not, is there any workaround. Any advice would be appreciated.

    Thank you.
  2. #2
    Yes, it is possible, your code should work fine
  3. #3
    Hello,
    Thanks for the reply. I found out that if the button is in a from with attribute MonitorValid="true" and the button is the subject of Client Validation event, then making it disabled after the click won't work.

    Thanks!
  4. #4
    Please post your test case
  5. #5
    @Thesti I think you can solve your problem, but need keep two things in mind.

    1. Add this property to the button FormBind="false"

    2. You need to run first the listener. Returning true causes a DirectEvent to be fired.

    <ext:Button ID="ButtonItemSave" runat="server" Text="Save" Icon="Disk" FormBind="false">
        <Listeners>
            <Click Handler="
                    if ( !#{PanelForm}.getForm().isValid() ) { 
                            // Show all invalid field with error
                            #{PanelForm}.validate();
                            return false;
                    } else { 
                            // Run DirectEvent
                            return true;
                    }" />
        </Listeners>
        <DirectEvents>
            <Click OnEvent="ButtonItemSave_Click"></Click>
        </DirectEvents>
    </ext:Button>
    Now when the user click ButtonItemSave and the form is not valide, he see all the error but not take action. If form is valid then do ButtonItemSave_Click.

    This post can help if you need more info:
    http://forums.ext.net/showthread.php...-form-is-valid

Similar Threads

  1. Replies: 7
    Last Post: Sep 02, 2016, 7:47 PM
  2. Add DirectEvent listener to dynamic TabPanel
    By JerryThorpe in forum 1.x Help
    Replies: 2
    Last Post: Oct 11, 2011, 7:19 PM
  3. [CLOSED] using listener to call code behind (ajax)
    By nhg_itd in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Sep 15, 2011, 11:56 AM
  4. [CLOSED] Call remote WebService via DirectEvent
    By macap in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 06, 2011, 1:44 PM
  5. [CLOSED] How to call more than one action with a listener?
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 13, 2010, 6:52 PM

Tags for this Thread

Posting Permissions