How to implement a file download in ASP.NET AJAX

前端 未结 4 1361
-上瘾入骨i
-上瘾入骨i 2021-02-04 15:22

I would like to use standard ASP.NET file download response, like in other Stack Overflow question.

Response.ContentType = \"application/octet-stream\";
Respo         


        
4条回答
  •  深忆病人
    2021-02-04 16:25

    I was able to solve this by calling a javascript function, which calls __doPostBack with no __EVENTTARGET.

     function GxGridView_Export(exportLink, exportType) {
         var containingGrid = $(exportLink).closest("table .GxGridViewWithSlider");
         __doPostBack('', containingGrid.attr('id') + "###" + exportType);
     }
    

    The server side Grid then parses the __EVENTARGUMENT and renders the export file.

    var eventArg = Page.Request.Form["__EVENTARGUMENT"];
    if (!string.IsNullOrEmpty(eventArg) && eventArg.Contains("###"))
    {
        var eventParams = eventArg.Split(new string[] { "###" }, StringSplitOptions.RemoveEmptyEntries);
        if (eventParams.Length == 2 && eventParams[0] == this.ClientID)
        {
            ExportGrid(eventParams[1]);
            return;
        }
    }
    

提交回复
热议问题