如何在ASP.net中单击上载按钮时使用Uploadify时向服务器发送其他数据

时间:2013-05-01 20:03:49

标签: jquery asp.net uploadify

我想使用Uploadify jQuery插件在ASP.net上传文件。但是当用户选择一个文件并点击“上传”按钮时按钮我想向服务器发送一些额外的参数。我写了这段代码:

     <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> 

当用户点击BrandName链接时,我想将用户选择的文件以及BrandAbbrbb发送到服务器。但是此代码会发送空的BrandNameBrandAbbr值。

编辑:我编写此代码,但我在undifine

中收到错误uploadifySettings
<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>

请帮帮我。感谢

1 个答案:

答案 0 :(得分:1)

您可以通过formData发送其他数据。 return to the Documentation

<强>更新 无论如何,文档中呈现的方式对我来说效果不佳。我使用了这段代码并且它正在工作

   $('#uploadify_1').uploadifySettings('property_something', 'value_something');