[CLOSED] close Ext.Net Window after export to excel

  1. #1

    [CLOSED] close Ext.Net Window after export to excel

    Hi ,

    I am exporting set of data to excel using some 3rd party control. The feature is working fine and i get the exported contents in excel.

    I have used a ext.net window that has "FileName" textfield and "Export" button as below:

    @(Html.X().Window()
            .Title("Export")
            .Hidden(true)
            .Width(750)
            .ID("ViewPopUp")
            .Height(400)
            .Layout(LayoutType.Fit)
            .Icon(Icon.Application)
            .Items
            (
            X.Container().ID("cntExport")
            .Items(
            X.TextField().ID("txtExpFName"),
            X.Button().ID("btnExp").Text("Export").Listeners(l => l.Click.Fn ="ExportClick1")
            )
            ))
    On the Click i have below code:

    Ext.net.DirectMethod.request({
                    url: '@Url.Action("Export", "Results")',
                    cleanRequest: true,
                    isUpload: true,
                    params: {
                        id: someid
                    },
                    success: function (data)
                    {                 
                        if (data.data == 'No data Found')
                        {
                            Ext.Msg.alert('Error', 'Cannot Export with no data.');
                        }
                     App.ViewPopUp.close();
                    },
                    failure: function (result)
                    {               
                    }
                });
    and my MVC action is as below:

    public ActionResult Export(int id)
            {
    var result = _svc.getData(id)
     if (result.Count == 0)
                            {                           
                                return new DirectResult(new { data = "No data Found" }) { IsUpload = true };
                            }
     else
                            {
                                 HttpContext.Response.Clear();
                 Response.Buffer = true;
                    Response.AddHeader("content-disposition", string.Format("attachment;filename={0}{1}", fileName, ".xlsx"));
                    Response.Charset = "";
                    Response.ContentType = "application/vnd.xlsx";
                    Response.OutputStream.Write(result, 0, result.Length);
                    Response.Flush();
                    Response.End();            
     return this.Direct();
    
                            }
    }
    So when there is no result it comes in the success function . But if there is some result it writes to response and show it in the browser as dialog but it doesnt not close the ext.net window.

    How can i achieve that? What is missing.

    Please let me know
    Last edited by Daniil; Sep 10, 2013 at 5:30 AM. Reason: [CLOSED]
  2. #2
    Hi @PriceRightHTML5team,

    Unfortunately, AJAX download request doesn't fire success and failure events. Generally speaking, there is no a direct solution unless using another things to download, for example, by Flash.

    However, there is some trick which might suite your needs.
    http://forums.ext.net/showthread.php...ll=1#post83757

Similar Threads

  1. Export to Excel
    By JonC in forum 1.x Help
    Replies: 9
    Last Post: Nov 13, 2012, 4:59 AM
  2. Replies: 0
    Last Post: Jul 30, 2012, 3:32 PM
  3. Export to Excel
    By ChrisO in forum 2.x Help
    Replies: 1
    Last Post: Jun 21, 2012, 4:08 PM
  4. Excel Export
    By maephisto in forum 1.x Help
    Replies: 1
    Last Post: May 13, 2011, 11:47 AM
  5. vb example of export to Excel
    By grosenbrock in forum 1.x Help
    Replies: 2
    Last Post: Aug 27, 2010, 6:22 PM

Tags for this Thread

Posting Permissions