I am using Uploadify with ASP.Net 4.0 and a Generic Handler for the backend. now I could use the scriptData part of Uploadify If I only knew how to read the JSon that is being posted to the Generic Handler so instead I opted for just sending the needed data through querystring which I have tested by hardcoding the query string and it works but when I try to get the value of a checkbox using the val() option it just passes the value of "on" no matter if the check box is or is not checked. I have also tried simply using $('#mainimg').is(':checked') which does not give me anything.
$('#file_upload').uploadify({
'uploader': '/uploadify/uploadify.swf',
'script': '/services/Upload.ashx?ismain=' + $('#mainimg').val(), <--- HERE IS THE PROBLEM
'multi': false,
'fileExt': '*.jpg;*.gif;*.png',
'sizeLimit': 10000000,
'scriptAccess': 'sameDomain',
'cancelImg': '/uploadify/cancel.png',
'onAllComplete': function (event, data) {
alert(data.filesUploaded + ' files uploaded successfully!');
},
'onCancel': function (event, ID, fileObj, data) {
alert('The upload of ' + fileObj.name + ' has been canceled!');
},
'onError': function (event, ID, fileObj, errorObj) {
alert(errorObj.type + ' Error: ' + errorObj.info);
},
'onSelectOnce': function (event, data) {
alert(data.filesSelected + ' files were selected for upload.');
},
'auto': true
});
I've set the value of the checkbox using this
$('#mainimg').click(function () {
if ($('#mainimg').is(':checked')) {
$('#mainimg').val('true');
}
else { $('#mainimg').val('false'); }
alert($('#mainimg').val());
});
I have even tried setting a variable using this code
$('#mainimg').click(function () {
if ($('#mainimg').is(':checked')) {
checkboxStatus = false; ;
}
else { checkboxStatus = true; }
alert(checkboxStatus);
});
But even though I would test it with an alert and it shows the right data in the alert when it goes to the uploadify script it just provides the value of 'false'
can anyone see what it is that I am doing wrong here?
You are right that the value for the checkbox is always "on", so you have to send something else if the checkbox is checked, i.e. the text of the checkbox, or its label's value.
(...)'script': '/services/Upload.ashx?ismain=' + $('#mainimg').is(':checked')?'true':'false',