Trying to solve a issue with a long running report adn letting the user know to wait

2 posts, 0 answers
  1. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 10 Feb 2015 Link to this post

    So I posted a question on the ASP.NET forums @ Microsoft and I have not gotten any useful suggestions on how to solve this issue.  I am hoping perhaps a telerik tool might be able to solve this issue...

    If you know of something please point me in the right direction... 
    here is the original post.. I have copied it below...

    QUICK COMMENT: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.

    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");

  2. Marin Bratanov
    Marin Bratanov avatar
    4652 posts

    Posted 12 Feb 2015 Link to this post

    Hello Warren,

    An AJAX request cannot send you a file as sending a file requires the headers to be modified, while an XHR request has a very strict structure.

    What I can suggest you consider is the following:

    1. Direct the entire browser to the handler and add the content-disposition: attachment header, so the current page will stay in the browser and the file will be treated as a popup window so it does not interfere with the user's workflow.
    2. Since the report runs for a long time, you can use the client-side click of the link to show a message and a cookie in the response together with an interval to know when to hide it. The approach is outlined in the following code library entry: The issue is that there are no events that notify the developer the file has been received in the browser, or that the save/open dialog has been shown, etc. Simply, the developer cannot know what happens with files on the user's machine. Thus, this approach may not be universal and may not work in all cases.
    3. Once you can fire JS functions for the request start and response end, you can consider the UI that you can show to the user. Perhaps the simplest approach is to use a RadNotification control, as it has both show() and hide() client-side methods, it provide a nice UI and it also offers the AutoCloseDelay property that lets it hide automatically after a while in case something goes amiss with the cookie approach.

    This, actually, is not related to our controls but to the generic way browsers handle this and, therefore, we do not have a control that can do this automatically for you.

    Marin Bratanov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top