So I am currently trying to figure out how to use AJAX, JQUERY, BLOCKUI and ASHX handlers to generate a very large report in CSV.  The report generation is spawned by clicking on a hyperlink which will call a javascript function that will execute a AJAX call.  As of right now I get the ajax call to execute, but I have not yet figured out how to get the ajax success method to dump the report to the calling client browser yet.

So this is the question I posted on ASP.NET… If I get an answer that works I will update this post with that info and a link to a code example set.


How do I get the ashx handler to work with the master page to generate a report when the user clicks on the hyperlink.

I can get it to work if I just route the hyper link control directly to the ashx page, but I eventually need to add code to block the UI while this report being generated.  In the ajax, I am thinking I need to do some type of action to force the browser to kick out the report.. Just not sure what…

I have a master page with the following code:

<script type="text/javascript">
       function startReport(result) {
                url: "HTTPHandlers/TagExportHandler.ashx",
                context: document.body,
                success: function(){
                    //Eventually put code to block UI and etc while report is rendering...


In the markup I have a asp:hyperlink control…

  <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/HTTPHandlers/TagExportHandler.ashx" OnClick="startReport('');">Tag Export 2</asp:HyperLink>

Then I have a ASHX control that does the following..

   public void ProcessRequest(HttpContext context)
            using (var db = new TIPWebITDataContext())
                string _exportContent = "";
                int[] userDepartments = ((User)HttpContext.Current.Session["currentUser"]).Departments.ToArray();

                List<TagDetailsDepartments> tagsModelCsvDepartmentses = null;
                List<TagDetailsNonDepartments> tagModelCsvNonDepartmentses = null;

                var data = GetTagDetails(db, "");
                CsvContext cc = new CsvContext();
                using (var writer = new System.IO.StreamWriter(context.Response.OutputStream))
                    CsvFileDescription output = new CsvFileDescription
                        QuoteAllFields = true,
                        EnforceCsvColumnAttribute = true

                    context.Response.AddHeader("content-disposition", "attachment; filename=TagExport.csv");
                    context.Response.ContentType = "text/csv";

                    if (userDepartments.Count() > 1)
                        tagsModelCsvDepartmentses = ((IQueryable<TagDetailsDepartments>)data).ToList();
                        cc.Write(tagsModelCsvDepartmentses.ToList(), writer, output);
                        tagModelCsvNonDepartmentses = ((IQueryable<TagDetailsNonDepartments>)data).ToList();
                        cc.Write(tagModelCsvNonDepartmentses.ToList(), writer, output);
                    context.Response.StatusCode = 200;
                    cc = null;

                    output = null;

                data = null;

                tagsModelCsvDepartmentses = null;
                tagModelCsvNonDepartmentses = null;

                userDepartments = null;
                // context.Session.Add("TagExport", "Complete");