Welcome Guest Search | Active Topics | Sign In | Register

Intercepting the ClientSideOnCancel event for the AJAXUploader Options
Dan
Posted: Wednesday, October 28, 2009 2:27:46 PM
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
eo_support
Posted: Wednesday, October 28, 2009 2:46:32 PM
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
Dan
Posted: Wednesday, October 28, 2009 3:12:41 PM
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
eo_support
Posted: Wednesday, October 28, 2009 3:14:16 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Great. Thank you very much for the additional notes.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.