2012-08-11 39 views
0

Currentl我有一个uploadify多文件上传供用户上传图像,对于他们选择的每个图像,我希望允许他们输入一些描述,并且我将存储描述连同图像的URL到我的数据库,现在我已经生成了每个图像选择上传的文本框,但我如何将值传递给我的处理程序,以便将其存储在我的数据库?下面是我的代码C#.net JQuery Uploadify为每个文件存储表单数据

Uploadify JQuery的:

$(document).ready(function() { 
      $("#<%=FileUpload1.ClientID %>").uploadify({ 
       'swf': '../../Uploadify/uploadify.swf', 
       'uploader': 'Handler.ashx', 
       'auto': false, 
       'multi': true, 
       'buttonText': 'Select Photos', 
       'fileDesc': 'Image Files', 
       'fileTypeExts': '*.gif; *.jpg; *.png', 
       'queueSizeLimit': 12, 
       'onQueueComplete': function() { 
        window.location.reload(); 
       }, 
       'onSelect': function (file) { 
        $('#textboxtables').append("<tr><td style='height:50px; vertical-align:middle'><input type='text' id='" + file.name + "'/></td></tr>"); 
       } 

      }); 
     }); 

因此,对于每一个文件/图片我选择,我将生成的文件名作为ID的texbox一个tablerow的,但是现在我如何得到的值该文本框并将其传递给我的处理程序?

回答

0

你可以通过通过“FORMDATA”的属性处理程序值的jQuery uploadify

$("#<%=FileUpload1.ClientID %>").uploadify({ 
    // your existing stuff 
    'formData' : { 'query' : $(YourTextBoxId).val() } 
}); 

现在这个“查询”变量将传递查询字符串参数的文本框的值,你可以得到这个值在你的处理程序中通过请求[“query”]表达式。

2

我有解决方案:

$(function() { 

    $("#<%=FileUpload1.ClientID %>").uploadify(
    { 
    'swf': '../js/uploadify/uploadify.swf', 
    'uploader': '../uploader.ashx', 
    'auto': false, 
    'method': 'post', 
    'multi': true, 
    'buttonText': 'Select File(s)', 
    'folder': '../images', 
    'fileDesc': 'Image Files', 
    'fileExt': '*.jpg;*.jpeg;*.gif;*.png', 

    'onUploadStart': function (event, data) { //this is where you will send the form //data, but remember to get if from post in the .ashx file, by contex.Request["gallaryId"] 


     $("#<%=FileUpload1.ClientID %>").uploadify('settings','formData', 

     { 'gallaryId': $("#hiddenGallaryId").val() } //note hiddenGallaryId would //have the gallaryId which im sending through post , make sure it is rendered in your page(//i.e.not concealed by a multiview control e.t.c) 
     ); 
    }   

    }); 
}); 

HTML:

<asp:FileUpload ID="FileUpload1" runat="server" /> 
<input id="hiddenGallaryId" type="text" class="hiddenFields"/> 

<a href="javascript: $('#<%=FileUpload1.ClientID %>').uploadify('upload','*')">Click To Upload Files</a> 
+0

THKS,它的工作! :) – 2015-02-10 13:22:16