How to Send Additional Data to Server When using Uploadify when Clicking Upload Button in ASP.net

StackOverflow https://stackoverflow.com/questions/16325568

  •  13-04-2022
  •  | 
  •  

문제

I want use Uploadify jQuery plugin to upload files in ASP.net. But when a user selects a file and clicks the 'Upload' button I want send some additional parameters to the server. I have written this code:

     <a id="bb" href="#">Start Upload</a>&nbsp; 
     |&nbsp;<a href="javascript:$('#<%=fuBrandIcon.ClientID%>').fileUploadClearQueue()">Clear</a> 

     <table width="50%">
        <tr>
            <td>BrandName</td>
            <td>

                <input id="BrandName" type="text" />
            </td>
        </tr>
          <tr>
            <td>BrandAbbr</td>
            <td>

                  <input id="txtBrandAbbr" type="text" />
            </td>
        </tr>
          <tr>
            <td>
               Icon
            </td>
            <td>
                <asp:FileUpload ID="fuBrandIcon" runat="server" ClientIDMode="Static" />
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">

            </td>
        </tr>
    </table>
     <script type = "text/javascript">

         $(window).load(

     function () {
         alert($("#BrandName").val());
         $("#fuBrandIcon").fileUpload({

             'uploader': '../UplodyFile/uploader.swf',

             'cancelImg': '../UplodyFile/cancel.png',

             'buttonText': 'Browse Files',

             'script': 'PublicHandler.ashx',

             'folder': 'uploads',

             'fileDesc': 'Image Files',

             'fileExt': '*.jpg;*.jpeg;*.gif;*.png',

             'multi': false,

             'auto': false,
             'onUploadStart' : function(file) {
                 alert('Starting to upload ' + file.name);
             } 
           //  "scriptData": { 'BrandName': $("#BrandName").val(), "BrandAbbr": $("#txtBrandAbbr").val(), "ActionPage": "Brand", "Action": "Add" }

         });

         $("#bb").click(function() {

             $('#<%=fuBrandIcon.ClientID%>').fileUploadStart();

         });

     });






</script> 

I want to send the file selected by the user as well as BrandName and BrandAbbr to the server when the user clicks to bb the link. But this code sends empty BrandName and BrandAbbr values.

Edit: i write this code but i get error uploadifySettings in undifine

<script>

            $(function () {
                $("#file_upload").uploadify({
                    height: 30,
                    swf: '../img/uploadify.swf',
                    uploader: 'Handler.ashx',
                    width: 120,
                    auto: false
                });

                $('#file_upload').uploadifySettings('name', $("#Text1").val());
            });

    </script>

Please help me. Thanks

도움이 되었습니까?

해결책

You can send additional data through formData. return to the Documentation

Update: Anyway the presented way in the documentation didn't work well with me. I used this code and it's work

   $('#uploadify_1').uploadifySettings('property_something', 'value_something');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top