[CLOSED] Set a buttons DirectEvent through another DirectEvent

  1. #1

    [CLOSED] Set a buttons DirectEvent through another DirectEvent

    Im trying to set a buttons DirectEvent through another DirectEvent from another button but it does not fire. Help please

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
    
        <ext:Panel runat="server">
            <TopBar>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:Button runat="server" ID="btnTest" Text="Test">
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <Items>
                <ext:Button runat="server" ID="btnSetEvent" Text="Set Event">
                    <DirectEvents>
                        <Click OnEvent="SetEvent" />
                    </DirectEvents>
                </ext:Button>
            </Items>
        </ext:Panel>
    
        </form>
    </body>
    </html>
        public partial class TestPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            public void Click_Event(object sender, DirectEventArgs e)
            {
                X.Msg.Alert("Test", "Test").Show();
            }
    
            public void SetEvent(object sender, DirectEventArgs e)
            {
                btnTest.DirectEvents.Click.Event += Click_Event;
            }
    
        }
    Last edited by Daniil; Jun 05, 2014 at 2:26 PM. Reason: [CLOSED]
  2. #2
    Hi @dataworks,

    Yes, it is not going to work for some reasons.

    If you need to attach a server side handler on the fly you can use a combination of a client side listener and a DirectMethod. There is no problem to attach a client side listener on the fly. Please use the AddListener and On methods.
  3. #3
    Hello Daniil. Reason I need a DirectEvent is to trigger a file download so I need to set IsUpload="true". Is there a workaround for this? Or a way to do as listener? Thanks
    Last edited by dataworks; Jun 05, 2014 at 1:26 PM.
  4. #4
    It is possible with a DirectMethod.
    App.direct.DirectMethodName({
        isUpload : true,
        formId   : "form id"
    });
  5. #5
    Thanks for the response Daniil. Having a hard time here. I set the listener through:

    btnTest.Listeners.Click.Handler = "App.direct.Download({isUpload: true, formId: 'form1'})";
    But nothing happenes. Then tried using:

    btnTest.AddListener("click", "App.direct.Download({isUpload: true, formId: 'form1'})");
    But the event fires when the listener is added (when btnSetEvent is clicked and not when btnTest is clicked).

        public partial class TestPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            public void Click_Event(object sender, DirectEventArgs e)
            {
                X.Msg.Alert("Test", "Test").Show();
            }
    
            public void SetEvent(object sender, DirectEventArgs e)
            {
                btnTest.Listeners.Click.Handler = "App.direct.Download({isUpload: true, formId: 'form1'})";
                //btnTest.AddListener("click", "App.direct.Download({isUpload: true, formId: 'form1'})");
            }
    
            [DirectMethod]
            public void Download()
            {
                Response.Clear();
                Response.ClearHeaders();
                Response.Buffer = true;
                Response.AddHeader("Content-Length", FileMgr.getContent("C:/test.txt").Length.ToString());
                Response.ContentType = "text/plain";
                Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.HtmlEncode("test.txt"));
                Response.BinaryWrite(FileMgr.getContent("C:/test.txt"));
                Response.Flush();
                Response.End();
            }
        }
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
    
        <ext:Panel runat="server">
            <TopBar>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:Button runat="server" ID="btnTest" Text="Test">
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <Items>
                <ext:Button runat="server" ID="btnSetEvent" Text="Set Event">
                    <DirectEvents>
                        <Click OnEvent="SetEvent" />
                    </DirectEvents>
                </ext:Button>
            </Items>
        </ext:Panel>
    
        </form>
  6. #6
    Please try:
    btnTest.AddListener("click", "function() { App.direct.Download({isUpload: true, formId: 'form1'}) }");
  7. #7
    Works! Thank you very much Daniil.
  8. #8

    How to send parameters to listener with options

    Ive been searching for a while but haven't had luck. I want to send a parameter to the DirectMethod defined on the listener. Thanks

                    Ext.Net.MenuItem mni = new Ext.Net.MenuItem();
                    mni.ID="mniRev"+row["EXPEDIENTE_RENEWAL_FORM"].ToString();
                    mni.Text="Revisi?n: "+row["EXPEDIENTE_RENEWAL_FORM"].ToString();
                    mni.AddListener("click", "function() { App.direct.Click_Event({isUpload: true, formId: 'form1'}); }");
                    mni.Render(mnuPrint, RenderMode.AddTo, true);
            [DirectMethod]
            public void Click_Event(string revID)
            {
                OpenPrint(revID);
            }
    Last edited by dataworks; Jun 05, 2014 at 8:17 PM.
  9. #9
    I want to send a parameter to the DirectMethod defined on the listener
    Just pass it as the first argument of the function call, and your optional config as the second argument.
    Geoffrey McGill
    Founder
  10. #10
    Also there is an example of that, please see #3:
    https://examples2.ext.net/#/Events/D...hods/Overview/

Similar Threads

  1. Replies: 5
    Last Post: Mar 19, 2014, 3:35 AM
  2. Replies: 9
    Last Post: Feb 22, 2014, 5:02 AM
  3. Replies: 1
    Last Post: Jun 09, 2011, 7:04 PM
  4. [CLOSED] Adding a button directevent in a directevent method
    By ogokgol in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 31, 2011, 10:29 AM
  5. Replies: 2
    Last Post: Oct 22, 2010, 11:04 AM

Posting Permissions