2012-08-11 37 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