views:

543

answers:

2

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

+1  A: 

I noticed in my own script that I'm using an onComplete event instead of onAllComplete. Unless a config option escapes me, onComplete will trigger after each Upload.aspx call (the files are uploaded individually - again maybe this is configurable). According to the documentation, onAllComplete doesn'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 response parameter. You can simply have it output the id of the element the script created and the response should contain the appropriate string.

Koobz
I thought it broke the swf's functionality if it didn't return a 0 or 1 after each upload....Not sure why I thought that....Well, isn't that nice. =D Thanks.
Blankasaurus
A: 

As promised, I made a video tutorial on how to use an Uploadify control in an ASP.Net application.

http://casonclagg.com/articles/6/video-tutorial-uploadify-asp-net-c-sharp.aspx

Hope this helps.

The short answer to my questions is this:

When you return context.Response.Write("foo"); out of your Upload.ashx handler...

And put this in your uploadify control:

 'onComplete': function(event, queueID, fileObj, response, data) {
    alert(response);
 }

An alert box with the word foo will pop up.

You can make this something more complicated like

context.Response.Write("id=55&title=This is the title");

and parse the values out yourself in your OnComplete or OnAllComplete in JQuery.

Blankasaurus