calling a function without a page load event?

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

I'm storing data on all of the files we upload to our site in a database.

Instead of just linking directly to the file, I'd like to link to a page
that will then grab the file and update a count in the DB (for traching
which documents get the most downloads).

I could easily do this by sending the document link to a new URL, passing a
querystring, and have that page then stream the file.

Is there a way to do this without having to actually refresh the page in the
end-user's browser, though? I'm guess I'd have to use some compliled
server-side script for this outside of the current app?

-Darrel
 
As the content is not to be displayed by the browser, the current window
is
left intact (is this what you are looking for ?).

Not quite. I think that would work if I am linking directly to the file. But
I'm not. And, the more I think about it, there probably isn't a way to do
what I want without a page load.

I was thinking of this process:

page: link -> downloadfile.aspx?file=fileX
downloadfile.aspx = adds a '1' to the file's download count and streams
fileX to the browser.

I was wondering if there was a way to get downloadfile.aspx to execute but
not actually load the page. But, the more I look at that, the more I realize
that that would be rather impossible. ;o)

-Darrel
 
Still not sure what you are looking for... Have you checked this article ?
It doesn't do direct linking.

downloadfile.aspx executes and the page_load event is executed (this is not
a problem, this is just executes what you want server side) and the current
page is not replaced. Is this what you are looking for ?

If yes, it should definitely work. Show us the code (you perhaps forgot to
clear the HTML content or to use the proper headers so that the browser
understand that it should not display the content but raise the download
file dialog).
 
downloadfile.aspx executes and the page_load event is executed (this is
not
a problem, this is just executes what you want server side) and the
current
page is not replaced. Is this what you are looking for ?

Umm...yea, I think so, though I didn't quite get that from the article.

So, the page I link to that streams the file...the aspx page...that page
should have different headers?

-Darrel
 
The page you use to stream the file uses a header that "tells" the browser
that this is NOT HTML content (but for example a "file attachment").

This way the browser :
- raises the "open/save as" dialog so that the user can open or save the
file on disk
- as the browser knows this is not HTML content (as it raises this dialog
instead), the browser has no reason to replace the current HTML page...

The article I mentionned earlier is for ASP but it applies as well to
ASP.NET as this is actually a client side issue (you just have server side
to send the proper HTTP header so that the browser reacts accordingly).

This is how it works...
 
Back
Top