None of Success, Failure, or Complete gets called on DirectEvent

  1. #1

    None of Success, Failure, or Complete gets called on DirectEvent

    I am exporting an Excel file on the click of a button. This is in my View:

                <ext:Button runat="server" ID="btnExport" Text="Export" StandOut="True" Icon="PageWhitePut" ToolTip="Export to an Excel file" AutoPostBack="False">
                    <DirectEvents>
                        <Click Timeout="600000" 
                            IsUpload="True"
                            OnEvent="ToExcel"
                            Before="Ext.Msg.wait('Please wait while the report is being generated. This may take a few minutes.', 'Please Wait...');"
                            Success="Ext.Msg.alert('Success', 'Yay');"
                            Failure ="Ext.Msg.alert('Error', result.errorMessage);"
                            Complete="Ext.Msg.alert('Complete', 'Done');">
                            <ExtraParams>
                                <ext:Parameter Name="selections" Value="#{GridPanel1}.getRowsValues({selectedOnly:true})" Mode="Raw"/>
                            </ExtraParams>
                        </Click>
                    </DirectEvents>
                </ext:Button>

    This is in my controller:
            protected void ToExcel(object sender, DirectEventArgs e)
            {
                // get the data...
    
                var eSubmit = new StoreSubmitDataEventArgs(json, null);
                System.Xml.XmlNode xml = eSubmit.Xml;
    
                this.Response.Clear();
                this.Response.ContentType = "application/vnd.ms-excel";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=myfile.xls");
    
                var xtExcel = new System.Xml.Xsl.XslCompiledTransform();
    
                xtExcel.Load(Server.MapPath("Excel.xsl"));
                xtExcel.Transform(xml, null, this.Response.OutputStream);
                
                this.Response.End();
            }
     
        }
    I want to hide the "Ext.Msg.wait" dialog when "ToExcel" finishes, but can't figure out how to do that... "Success", "Failure", and "Complete" never get called so I can't do it in any of those places. What can I do?
  2. #2
    If file is returned the the page doesn't call any events therefore direct event doesn't fire events also
  3. #3
    I see.
    So how can I return a file, as well as showing and dismissing a wait dialog?
  4. #4
    I guess no solution, file downloading is handled by a browser and we have no any events after downloading
    Therefore do not use waiting dialog
  5. #5
    Is there anything else you can suggest? Getting the data takes up to a minute and I would like to display something to the user during that time, so they know something is actually happening.
  6. #6
    I can suggest to make ajax request and start async file generation
    After that polling the server with some interval to check that file is ready. If file is ready then generate link (anchor tag) to download generated file

    See the following sample how to organize polling
    https://examples2.ext.net/#/TaskMana...c/Poll_Server/
  7. #7
    I got the polling working by following the example, thanks.

    However I'm still stuck on the file download. I don't understand what you mean by "generate link (anchor tag) to download generated file".
    I tried the following, but this.Response isn't working in the ToExcel function (I get "value does not fall within the expected range" on the AddHeader line)

            protected void StartLongAction(object sender, DirectEventArgs e)
            {
                var jsonSelections = e.ExtraParams["selections"];
                var serializer = new JavaScriptSerializer();
                var selections = serializer.Deserialize<Dictionary<string, string>[]>(jsonSelections);
    
                this.Session["LongAction"] = 0;
                ThreadPool.QueueUserWorkItem(state => ToExcel(selections));
                this.ResourceManager1.AddScript("{0}.startTask('longaction');", this.TaskManager1.ClientID);
    
                e.Success = true;
            }
    
            protected void ToExcel(Dictionary<string, string>[] selections)
            { 
                HttpContext.Current = this.Context;
                var report = CustomerReconcileLayer.GetReport(selections);
                ReportStore.LoadData(report);
                string json = new JavaScriptSerializer().Serialize(report);
    
                var eSubmit = new StoreSubmitDataEventArgs(json, null);
                System.Xml.XmlNode xml = eSubmit.Xml;
    
                this.Response.Clear();
                this.Response.ContentType = "application/vnd.ms-excel";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=Export.xls");
    
                var xtExcel = new System.Xml.Xsl.XslCompiledTransform();
    
                xtExcel.Load(Server.MapPath("Excel.xsl"));
                xtExcel.Transform(xml, null, this.Response.OutputStream);
    
                this.Session.Remove("LongAction");
    
                this.Response.End();
            }
    Last edited by KBorkiewicz; Aug 22, 2013 at 9:24 PM.

Similar Threads

  1. [CLOSED] Store OnBeforeStoreChanged success / failure callbacks?
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Nov 21, 2012, 7:35 PM
  2. DirectMethod success and failure not working
    By mtrutledge in forum 1.x Help
    Replies: 3
    Last Post: Mar 14, 2012, 1:08 PM
  3. Replies: 7
    Last Post: Nov 29, 2011, 7:07 AM
  4. Replies: 1
    Last Post: Jun 09, 2011, 7:04 PM
  5. Replies: 2
    Last Post: Dec 01, 2010, 10:14 AM

Tags for this Thread

Posting Permissions