I have an Send.aspx page that has an uploadify control on it. Upload.ashx handles the file upload.
I am adding a file record to a sql database in the Upload.ashx file and I need to get the ID of that record back from Upload.aspx when it is done.
Can’t get it working with Sessions. =( Something to do with an Adobe bug?
What would the best way to handle this be?
Here is the uploadify control:
<script type="text/javascript">
// <![CDATA[
var contestID = $('[id$=HiddenFieldContestID]').val();
var maxEntries = $('[id$=HiddenFieldMaxEntries]').val();
var userID = $('[id$=HiddenFieldUserID]').val();
$(document).ready(function() {
$('#fileInput').uploadify({
'uploader': '../uploadify/uploadify.swf',
'script': '../uploadify/Upload.ashx',
'scriptData': { 'contestID': contestID, 'maxEntries': maxEntries, 'userID': userID },
'cancelImg': '../uploadify/cancel.png',
'auto': true,
'multi': false,
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.png;*.jpeg',
'queueSizeLimit': 1,
'sizeLimit': 4000000,
'buttonText': 'Choose Image',
'folder': '/uploads',
'onAllComplete': function(event, queueID, fileObj, response, data) {
document.getElementById('<%= ButtonCleanup.ClientID %>').click();
}
});
});
// ]]></script>
This took a while for me to figure out. But in retrospect it is extremely simple. For this reason, I mad a video tutorial to help newcomers get started quickly and understand how this awesome control works.
Video Tutorial from start to finish:
http://casonclagg.com/articles/6/video-tutorial-uploadify-asp-net-c-sharp.aspx
I noticed in my own script that I’m using an
onCompleteevent instead ofonAllComplete. Unless a config option escapes me,onCompletewill trigger after each Upload.aspx call (the files are uploaded individually – again maybe this is configurable). According to the documentation,onAllCompletedoesn’t actually pass back request data (which makes sense because it’s done outside of the scope of the individual uploads).Anything that Upload.aspx outputs should appear in the
responseparameter. You can simply have it output the id of the element the script created and the response should contain the appropriate string.