Uploadify pass formdata variable to handler.ashx

梦想的初衷 提交于 2019-12-10 12:20:01

问题


I am trying to send parameters from my .aspx page into my handler.ashx with the help of "formdata" in uploadify using .net and c# when I upload a file. The parameters are take from textboxes that have values in the. The code is:

 <script type = "text/javascript">
     $(document).ready(function() {
         $("#<%=FileUpload1.ClientID %>").uploadify({
             'swf': 'Scripts/uploadify.swf',
             'uploader': 'Handler.ashx',
             'auto': true,
             'multi': true,
             'buttonText': 'Select File(s)',
             'removeCompleted' : false,
             'fileTypeDesc' : 'PDF Files',
    'fileTypeExts' : '*.pdf',
    'formData' : { "id": "<%=TBcustnom.Text %>", "pwd": "<%=Pwd.Text %>" }


         });
     });

handler.ashx only receives the first value (id), but not whats in the pwd part.

string id = context.Request["id"]; 
string pwd = context.Request["pwd"];

How do I configure the javascript to send both parameters? or how do I configure the handler.ashx to receive the pwd as well?

Best regards


回答1:


var data = {};
data.id = <%TBcustnom.Text %>;
data.pwd = <%Pwd.Text %>;

$(document).ready(function () {
    $("#<%=FileUpload1.ClientID %>").uploadify({
        'swf': 'Scripts/uploadify.swf',
        'uploader': 'Handler.ashx',
        'auto': true,
        'multi': true,
        'buttonText': 'Select File(s)',
        'removeCompleted': false,
        'fileTypeDesc': 'PDF Files',
        'fileTypeExts': '*.pdf',
        'formData': obj: JSON.stringify(data)
    });
});

In the server side,

var jsonString = context.Request["obj"];
var serializer = new JavaScriptSerializer();
var jsonObjects = serializer.Deserialize<Dictionary<string, string>>(jsonString);



回答2:


The only thing I needed to do was to look at the right place.

string id = context.Request["id"]; 
string pwd = context.Request["pwd"];

this is supposed to be

string id = context.Request.Form[1]; 
string pwd = context.Request.Form[2];

Take care!



来源:https://stackoverflow.com/questions/17043672/uploadify-pass-formdata-variable-to-handler-ashx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!