[CLOSED] Close eventmask when file is downloaded using DirectEvent

  1. #1

    [CLOSED] Close eventmask when file is downloaded using DirectEvent

    Hey Team,

    I have query related to DirectEvent and using eventmask along with DirectEvents.

    My controller action is returning the file which is generated using another function GenerateFile method which is returning the file path.

    Public Function PdfDownload() As ActionResult
             Dim genFilePath = GenerateFile(FileExtension.PDF,  "templateFileName")
             Dim fileBytes As Byte() = System.IO.File.ReadAllBytes(genFilePath)
             Dim response = New FileContentResult(fileBytes, "application/octet-stream")
             response.FileDownloadName = System.IO.Path.GetFileName(genFilePath)
             Return response
    End Function

    View

    @Html.X().Button().Text("Download").DirectEvents(Sub(ls)
    ls.Click.EventMask.ShowMask = True
    ls.Click.Url = Url.Action("BillingPdfDownload")
    ls.Click.IsUpload = True
    End Sub)
    Issue is with EventMask, which never gets closed, because in this case result was never returned from action. Usually we put Me.Direct() and then eventmask gets to know that event is completed. But in our case I dont think we can put response anywhere inside Me.Direct() method as a result.


    Anyone knows how to close the eventmask after file is being downloaded?
    Last edited by fabricio.murta; Jul 15, 2016 at 5:10 PM.
  2. #2
    Hello @mwiater!

    Unfortunately, that's not possible at all without maybe some third-party tools like, maybe using SWF objects.

    The problem is because the web browsers do not interact back to the page in the event of a file download being completed. The best that can be done is remove the mask as soon as the file download is sent. In other words, immediately after the server replies with the file download handle, not before the client finishes the download.

    If you search the forums you are going to find several other threads about this problem, possibly this one has good alternatives for you: How to show and Hide mask while saving file to local?

    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi Fabricio,

    Taking reference form given thread, I was able to close the eventmask when file is being downloaded.

    Thanks.
  4. #4
    Hello! Glad it was helpful! We would really appreciate if you shared which approach worked for you in your case. Could be useful for others in the future!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Upload File using DirectEvent
    By Daniil in forum Examples and Extras
    Replies: 2
    Last Post: Jul 04, 2014, 6:22 AM
  2. Download File using DirectEvent
    By Daniil in forum Examples and Extras
    Replies: 0
    Last Post: Dec 13, 2013, 4:02 AM
  3. Replies: 2
    Last Post: Jul 04, 2013, 1:10 PM
  4. [CLOSED] MVC DirectEvent Download File
    By MWM2Dev in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 17, 2013, 11:49 AM
  5. [CLOSED] [1.0] DirectEvent File Download
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jan 21, 2011, 6:04 PM

Posting Permissions