[CLOSED] Delete / Remove directevent handler in code behind

Page 2 of 2 FirstFirst 12
  1. #11
    I understand a bit more why the sample code I gave you before didn't work the way I expected, but I am still having a case that I cannot produce in a sample where -= doesn't work, so I've resorted to setting Before="return false;". However, I found another situation where Confirmation will still show even though.

                    <ext:Button ID="Btn" runat="server" Text="Test">
                    <Listeners>
                        <Click Handler="alert('test');" />
                    </Listeners>
                    <DirectEvents>
                        <Click OnEvent="OnClick" Before="return false;">
                        <Confirmation ConfirmRequest="true" Message="Are you sure?" Title="Confirm" />
                        </Click>
                    </DirectEvents>
                    </ext:Button>

    This will deactivate the OnEvent from ever being triggered, but not the ConfirmRequest. It's kind of frustrating that presently if I want to turn off the click event in the server-side, I have to deactivate both the Click Event Before="return false" and set the Confirmation.ConfirmRequest="false" just to prevent confusion to the user.

    In the meantime, till you guys have a more robust situation, the following extension method allows me (or anyone) to reliably Disable any event Event as long as its a part of the Page_Load(). I'll have to wait till you have a solution on the DirectEvent side.
            public static void DisableEvent( this ComponentDirectEvent evt ) {
                var before = evt.Before;
                if( !string.IsNullOrEmpty( before ) )
                    evt.Before = "return false;;" + before;// 2 semicolons are used to indicate intensional override
                else
                    evt.Before = "return false;;";
                if( evt.Confirmation.ConfirmRequest )
                    evt.Confirmation.ConfirmRequest = false;
            }
    
    
            public static void EnableEvent( this ComponentDirectEvent evt ) {
                var before = evt.Before;
                if( !string.IsNullOrEmpty( before ) && before.StartsWith( "return false;;" ) )
                    evt.Before = before.Substring( 14 );
                if( evt.Confirmation.ConfirmRequest == false && !string.IsNullOrEmpty( evt.Confirmation.Message ) )
                    evt.Confirmation.ConfirmRequest = true;
            }
    Last edited by michaeld; Oct 06, 2013 at 12:13 PM.
  2. #12
    Generally speaking, the "-=" thing detaches the server side handler only. It doesn't do anything on client.

    Something has been committed to the SVN trunk.

    1. The suspendEvent/resumeEvent methods work for a DirectEvent. So, this examples is fully functioning.

    Example SuspendEvent/ResumeEvent
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("Button_Click", "Click DirectEvent").Show();
        }
     
        protected void Suspend(object sender, DirectEventArgs e)
        {
            this.Button1.SuspendEvent("click");
        }
     
        protected void Resume(object sender, DirectEventArgs e)
        {
            this.Button1.ResumeEvent("click");
        }
    </script>
     
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
     
            <ext:Button ID="Button1" runat="server" Text="Test">
                <Listeners>
                    <Click Handler="alert('Click Listener')" />
                </Listeners>
                <DirectEvents>
                    <Click OnEvent="Button1_Click" />
                </DirectEvents>
            </ext:Button>
     
            <ext:Button runat="server" Text="Suspend click event via JavaScript">
                <Listeners>
                    <Click Handler="App.Button1.suspendEvent('click');" />
                </Listeners>
            </ext:Button>
     
            <ext:Button runat="server" Text="Resume click event via JavaScript">
                <Listeners>
                    <Click Handler="App.Button1.resumeEvent('click');" />
                </Listeners>
            </ext:Button>
     
            <ext:Button runat="server" Text="Suspend click event via code behind" OnDirectClick="Suspend" />
     
            <ext:Button runat="server" Text="Resume click event via code behind" OnDirectClick="Resume" />
        </form>
    </body>
    </html>
    2. The new RemoveDirectListener has been appeared.

    Example RemoveDirectListener
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("Button_Click", "Click DirectEvent").Show();
        }
     
        protected void Remove(object sender, DirectEventArgs e)
        {
            this.Button1.RemoveDirectListener("click");
        }
    </script>
     
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
     
            <ext:Button ID="Button1" runat="server" Text="Test">
                <DirectEvents>
                    <Click OnEvent="Button1_Click" />
                </DirectEvents>
            </ext:Button>
     
            <ext:Button runat="server" Text="Remove DirectEvent via JavaScript">
                <Listeners>
                    <Click Handler="App.Button1.removeDirectListener('click');" />
                </Listeners>
            </ext:Button>
     
            <ext:Button runat="server" Text="Remove DirectEvent via code behind" OnDirectClick="Remove" />
        </form>
    </body>
    </html>
    Quote Originally Posted by michaeld View Post
    Also, I've tested setting Before="return false;" in a DirectEvent and it does nothing.
    Also I would like to demonstrate the following technique. It might be helpful in some scenarios.

    Examples DirectEvent's Before
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("Button_Click", "Click DirectEvent").Show();
        }
     
        protected void Lock(object sender, DirectEventArgs e)
        {
            this.Button1.Set("clickDirectEventlock", true);
        }
    
        protected void Unlock(object sender, DirectEventArgs e)
        {
            this.Button1.Set("clickDirectEventlock", false);
        }
    </script>
     
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
     
            <ext:Button ID="Button1" runat="server" Text="Test">
                <DirectEvents>
                    <Click OnEvent="Button1_Click" Before="return !this.clickDirectEventlock;" />
                </DirectEvents>
            </ext:Button>
     
            <ext:Button runat="server" Text="Lock DirectEvent via JavaScript">
                <Listeners>
                    <Click Handler="App.Button1.clickDirectEventlock = true;" />
                </Listeners>
            </ext:Button>
    
            <ext:Button runat="server" Text="Unlock DirectEvent via JavaScript">
                <Listeners>
                    <Click Handler="App.Button1.clickDirectEventlock = false;" />
                </Listeners>
            </ext:Button>
     
            <ext:Button runat="server" Text="Lock DirectEvent via code behind" OnDirectClick="Lock" />
    
            <ext:Button runat="server" Text="Unlock DirectEvent via code behind" OnDirectClick="Unlock" />
        </form>
    </body>
    </html>
  3. #13
    Okay, great. RemoveDirectListener allows me to remove a DirectEvent on postback. How to I restore it?
  4. #14
    I've also thought about this a little bit more from your .net programmer's perspective? Wouldn't it be wiser to add this method to the actual ObservableDirectEvent? It would be easier if we weren't expected to remember the extjs names that match the Events except on the client-side.

    So I'm thinking you already have the ConfigOption name available so it should be very easy to call something like, ...

    Button1.DirectEvents.Click.RemoveDirectListener();
    Button1.DirectEvents.Click.SuspendEvent();
    Button1.DirectEvents.Click.ResumeEvent();
    This way you have both the parent and the actual extjs listener name available and the programmer is ensured to reference the correct extjs listener without having to look it up. I realize this may be a little more work, but it seems like the right way to do it. Just a thought.

    Both options might be practical and I realize SuspendEvent(name) and ResumeEvent(name) might be appropriate to have in both places as well.

    And yeah, it would follow that the same should work for Listeners too.
    Button1.Listeners.Click.Remove();
    Button1.Listeners.Click.SuspendEvent();
    Button1.Listeners.Click.ResumeEvent();
    Curious though. Does SuspendEvent suspend both the DirectEvent and the Listener event with the same name?
    Last edited by michaeld; Oct 09, 2013 at 7:17 AM.
  5. #15
    We apologize for such the delay in responding.

    Quote Originally Posted by michaeld View Post
    Okay, great. RemoveDirectListener allows me to remove a DirectEvent on postback. How to I restore it?
    I don't see a simple way. If you need to remove and have a possibility to restore, it is better to operate with lock/unlock.

    Quote Originally Posted by michaeld View Post
    I've also thought about this a little bit more from your .net programmer's perspective? Wouldn't it be wiser to add this method to the actual ObservableDirectEvent? It would be easier if we weren't expected to remember the extjs names that match the Events except on the client-side.

    So I'm thinking you already have the ConfigOption name available so it should be very easy to call something like, ...

    Button1.DirectEvents.Click.RemoveDirectListener();
    Button1.DirectEvents.Click.SuspendEvent();
    Button1.DirectEvents.Click.ResumeEvent();
    This way you have both the parent and the actual extjs listener name available and the programmer is ensured to reference the correct extjs listener without having to look it up. I realize this may be a little more work, but it seems like the right way to do it. Just a thought.

    Both options might be practical and I realize SuspendEvent(name) and ResumeEvent(name) might be appropriate to have in both places as well.

    And yeah, it would follow that the same should work for Listeners too.
    Button1.Listeners.Click.Remove();
    Button1.Listeners.Click.SuspendEvent();
    Button1.Listeners.Click.ResumeEvent();
    Well, DirectEvents's names always match the client side Listeners'. Though, your suggestion is very good in API terms. Unfortunately, it is not that simple to implement and I am not sure it is worth enough.

    Quote Originally Posted by michaeld View Post
    Curious though. Does SuspendEvent suspend both the DirectEvent and the Listener event with the same name?
    Yes, it suspends both of them.
Page 2 of 2 FirstFirst 12

Similar Threads

  1. how to delete or remove record?
    By richard in forum 2.x Help
    Replies: 0
    Last Post: Jun 08, 2012, 9:12 AM
  2. Delete or remove record from gridpanel
    By lapix in forum 1.x Help
    Replies: 3
    Last Post: Feb 25, 2012, 5:56 PM
  3. Replies: 1
    Last Post: Jun 09, 2011, 7:04 PM
  4. Replies: 4
    Last Post: Mar 26, 2011, 7:06 PM
  5. [CLOSED] [1.0] Add handler during DirectEvent
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 22, 2010, 2:02 PM

Tags for this Thread

Posting Permissions