Click here to Skip to main content
15,915,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Another n00b ASP question:
I want to count downloads and trap some other on-page information when clients download a file from a href. So I need to fire some event and also do the normal href type download code. I don't care if the event fires before or after the download. It seems that if I put an event into the anchor block, the href is ignored and vice versa.

How can I do this? Asp and c#.

Thanks

Eric
Posted

You can attach a javascript at the click event of the hyperlink HyperLink1.Attributes.Add("onclick", "myAjaxFunction()");. In the javascript or jQuery function connect to server through ajax (xmlHttp or jQuery). The server side function will record the download. As hyperlink don't have postback events and don't have to post back you need to use ajax for this.

<a id="MainContent_HyperLink1" onclick="myAjaxFunction();" href="Test.jpg">HyperLink</a> for this markup javascript event trigger first then the download. Both works.
 
Share this answer
 
Comments
Sandeep Mewara 10-Apr-11 3:16am    
My 5!
http://stackoverflow.com/questions/2496583/asp-net-count-download-clicks[^]

I hope the above information will be helpful. If you have more concerns, please let me know.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900