File Download dialog events in ASP.NET

Posted on 2010-01-03
Last Modified: 2012-05-08
Hi Everyone,

I have been breaking my head over a problem from the past couple of days.
My problem is that I have to provide an option for the user to upload and download files to the server. I have already done this by providing the file upload control for uploading the file and later providing a link for all uploaded files in a gridview, clicking on which will download the file to client's local machine at the path of his choice. When the user clicks on the link he is prompted with a file download dialog after which he can choose to open or save the file or cancel the download.
What I am required to do is to set a flag in my database whenever a user downloads a file. To do this I need to find out which of the 3 buttons (Open, Save, Cancel) the user has clicked. Only if the user Opens/Saves the file, should I update the flag in the database. So is there any way either through javascript or ASP.NET that I can track such an event and update the flag.
Question by:Shashidhar_Shenoy
    LVL 15

    Accepted Solution


     i dont think that can be done... That is client side browser event. Instead u can make an update in to the database while he clicks the Link for the download

    Author Comment

    Thanks for the quick reply.

    In fact that is exactly what I am doing now. But the user could cancel the download after clicking on the download link. That is why I am trying to look for the events (if any) of file download dialog.

    Is there any alternate way in which I could achieve the same result?
    LVL 28

    Assisted Solution

    Agree with rajeeshmca. You can not do that. At the moment the user clicks the link, the file is transferred to the client (to the browser cache). The dialogue only asks the user what to do with the file which is already (partly) in their own cache.

    You should also realize that an HTTP-request is not necessarily done by a browser, or that every browser must have the same buttons.

    Author Comment

    Thanks guys for the reply. After a lot of googling around even I have come to a conclusion that it is not possible to do that. Instead I have chose to warn the user by using a javascript confirm dialog saying that if he proceeds then the flag will be set in the database. If he clicks OK on the confirm dialog then after that even if he chooses to cancel the download later the flag will be set in the database.

    Author Closing Comment

    Although I did not get a solution to my actual problem I atleast came to know that what I was trying to achieve was not possible and that I had to look for another alternative. Thanks to both the experts for their quick replies.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction (All good things must come to an end ( The original MySQL API ( has gone away, deprecated by PHP in Version 5.5, and removed from PHP in all curre…
    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now