Rank: Member Groups: Member
Joined: 6/3/2009 Posts: 27
|
I've set the ClientSideOnCancel event for our AJAXUploader so that it runs a javascript function on our page. Ideally, I'd like to prompt the user "Are you sure you want to cancel?" before they actually commit the cancel (accidental click, second thoughts, etc.) However, by the time my javascript function gets called, the actual upload process has already been terminated automatically by the control.
Is there a way for me to trap that before it gets that far? If someone accidentally cancels a large file, it's very frustrating having to restart. Also, understanding this would let me trap when someone mistakenly tries to navigate from the page before the upload is complete.
thanks, Dan
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, Yes. You can do that but you will need to use your own cancel button instead of the built-in cancel button. The build-in cancel button always cancels the upload right away. To use a custom cancel button, you will need to use LayoutTemplate to have a custom layout and remove the built-in cancel button first. You can then place some thing like this in the template:
Code: HTML/ASPX
<input type="button" value="Cancel" onclick="cancel_upload()" />
Note it calls JavaScript function cancel_upload when clicked. This is a function that you would provide:
Code: JavaScript
function cancel_upload()
{
//Cancel the upload only if user confirms
if (confirm("Are you sure"?))
eo_GetObject("AJAXUploader1").cancel();
}
Hope this helps. Thanks
|
Rank: Member Groups: Member
Joined: 6/3/2009 Posts: 27
|
Works great. Just a couple things for anyone else trying to do the same:
1. Be sure to remove/comment out the existing ClientSideOnCancel event declaration on your upload control before doing this. Otherwise, your javascript function will run twice.
2. Be sure to replace the "AJAXUploader1" in the eo_GetObject call with whatever ID you've set for your uploader control, if different.
thanks again, Dan
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Great. Thank you very much for the additional notes.
|