Welcome Guest Search | Active Topics | Sign In | Register

AJAX Uploader Delay Post Back Options
Sadjad Bahmanpour
Posted: Wednesday, August 14, 2013 6:01:08 PM
Rank: Member
Groups: Member

Joined: 6/19/2013
Posts: 23
Hi,

I've trying to 'Delay Post Back' using AJAX Uploader. But the way I'm using it is that I have submit button on the page that first call the ajax uploader to upload and then when it is finished, I'll do the postback. They problem is if I do the postback write away after javascript (ClientSide) uploadDone is called the PostFiles in the ServerSide is empty but if I do setTimeout for about 500 milliseconds, then I'll get the files in the ServerSide Click event.

<asp:UpdatePanel ID="UpdatePanel123" runat="server">
<ContentTemplate>

<eo:AJAXUploader runat="server" ID="AJAXUploader1" Width="400px" TempFileLocation="~/eo_upload" ProgressDialogID="AJAXUploaderProgressDialog1" MaxFileCount="1" MaxDataSize="100000" ClientSideOnError="uploadError" ClientSideOnDone="uploadCompleted">
<LayoutTemplate>
<table cellspacing="0" cellpadding="2" width="400" border="0">
<tr>
<td>
<asp:PlaceHolder ID="InputPlaceHolder" runat="server">Input Box Place Holder</asp:PlaceHolder>
</td>
</tr>
</table>
</LayoutTemplate>
</eo:AJAXUploader>

<asp:Button ID="btnSubmit" runat="server" Text="Save" OnClick="btnSubmit_Click" OnClientClick="javascript:return upload();" />

</ContentTemplate>
</asp:UpdatePanel>

JavaScripts:

function upload() {
//Get the AJAX uploader
var uploader = eo_GetObject("AJAXUploader1");
if (uploader.isEmpty())
return true;

uploader.upload();
return false;
}

function uploadCompleted(sender) {
window.setTimeout(function() {
<%= Page.ClientScript.GetPostBackEventReference(btnSubmit, string.Empty) %>;
}, 500);
}

function uploadError(control, error, message) {
alert(error + ' ' + message);
}

ServerSide C# code:

protected void btnSubmit_Click(object sender, EventArgs e)
{
EO.Web.AJAXPostedFile[] aaa = AJAXUploader1.PostedFiles;
}

If you just change the window.setTimeout delay from 500 to zero, you'll get no files on the server side code.
Sadjad Bahmanpour
Posted: Wednesday, August 14, 2013 8:31:19 PM
Rank: Member
Groups: Member

Joined: 6/19/2013
Posts: 23
And Also, I want after submit, since I use UpdatePanel + MultiView, When user click on add file again, I want to be enable the AjaxUploader again.

The problem is after Uploading the First File use that JS function, the file browse control get disabled and setting AJAXUploader.Enable = true and anything else would not enable the upload/browse button.

Thanks,
Sadjad Bahmanpour
eo_support
Posted: Wednesday, August 14, 2013 10:54:38 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

What you observed is an interesting behavior but indeed is how the code works. The AJAX uploader needs a short time (it also uses setTimeout(0)) in order to update its internal states. Only after those state information has been correctly updated, you will be able to post back the page and see PostedFiles. If you do it before, then it won't work. In your case, you can set the AJAXUploader's AutoPostBack to true instead of using ClientSideOnDone handler. That way the AJAXUploader will automatically posts back once upload is done.

The reason that your AJAXUploader is disabled after post back is because you have set MaxFileCount to 1. Remove that property and the uploader will be enabled again.

Thanks!
Sadjad Bahmanpour
Posted: Wednesday, August 14, 2013 11:47:12 PM
Rank: Member
Groups: Member

Joined: 6/19/2013
Posts: 23
Thanks for the fast reply as always.

Since I do to do some stuff and then postback, I think I'll stick with that setTimeout work around. But it would be the best if the component does whatever it is needed to be done before calling upload done in client side.

About MaxFileCount I'll try removing it and see what will happen. Anyways can you please explain the purpose of this property?

Thanks,
Sadjad Bahmanpour
eo_support
Posted: Thursday, August 15, 2013 9:16:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

The purpose of the property is to ensure that through our the whole session (until the browser close or page unload), the AJAXUploader can only be used post one file. If user want to upload another file, they must explicitly delete the previously uploaded file first. However in reality this property is rarely used.

Thanks!
Sadjad Bahmanpour
Posted: Thursday, August 15, 2013 7:22:07 PM
Rank: Member
Groups: Member

Joined: 6/19/2013
Posts: 23
Thanks, One more problem I have is that the AJAXUploader seems not to delete its temp files. I have waited for a day but the temp files are not deleted. I'm using V11.0.13.2

<form id="form1" runat="server">
<div>
<eo:AJAXUploader ID="AJAXUploader1" runat="server" Width="100%"
FinalFileLocation="C:\inetpub\wwwroot\eo_upload" ProgressBarSkin="Windows_Vista"
TempFileLocation="C:\inetpub\wwwroot\eo_upload" OnFileUploaded="AJAXUploader1_FileUploaded"
AutoPostBack="True" EnableKeyboardNavigation="True">
</eo:AJAXUploader>

<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</div>
</form>

And nothing on the C# end but two empty Event Handlers.
Sadjad Bahmanpour
Posted: Thursday, August 15, 2013 7:23:36 PM
Rank: Member
Groups: Member

Joined: 6/19/2013
Posts: 23
Forgot to mention, I've tried on my Local Development on VS 2008 and VS 2012 and I've tried on two servers on IIS 7.5
eo_support
Posted: Thursday, August 15, 2013 7:29:04 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

We are not aware of such problem. You may want to check your temp file's LastAccessTime and LastWriteTime. If they are recent then you may have some other program that's accessing those files (for example, index service, AntiVirus program, etc). If any program has accessed those files recently, then we won't delete it.

Also the AJAXUploader won't check the temp files if your AppDomain has been unloaded. This can happen if your server does not have any request for a while. So it's possible that you let the site sits for a day but in fact your site is not running at all, thus AJAXUploader is not even loaded in this case.

Thanks
Sadjad Bahmanpour
Posted: Thursday, August 15, 2013 7:42:52 PM
Rank: Member
Groups: Member

Joined: 6/19/2013
Posts: 23
So any if of those cases, I better clean-up the temp folder once in a while just ensure that disk-space is not wasted.
Sadjad Bahmanpour
Posted: Thursday, August 15, 2013 7:48:11 PM
Rank: Member
Groups: Member

Joined: 6/19/2013
Posts: 23
Also does AJAXUploader clean-up next time the AppDomain gets loaded? Or it does the clean-up only after the postback and only on those files for this upload request.

I mean if all those cases you've told me, do I need to clean-up once in a while or does the AJAXUploader would do it eventually.

Thanks,
Sadjad Bahmanpour
eo_support
Posted: Friday, August 16, 2013 12:13:39 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

No. You do not need to write code to clean up the temp file. As long as nobody else touch those files, the AJAXUploader will clean them up the next time it runs.

Thanks!
Sadjad Bahmanpour
Posted: Friday, August 16, 2013 3:10:02 PM
Rank: Member
Groups: Member

Joined: 6/19/2013
Posts: 23
But since, I have to read the files (Either TempFiles or FinalFiles) to write them to the Database, so anytime AJAXUploader1_FileUploaded is called the Files are going to be access by me. I use File.ReadAllBytes(AJAXUploader1.PostedFiles[0].TempFileName) but again the files are accessed. And also since I have no say on if the server has any AntiVirus or Indexer, seems like I have no choice but to delete them myself.
I've tried to wait for a day and called the application to upload another file so I know for sure the AppDomain is up again and the AjaxUploader is called again but no luck in files being delete by the component.


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.