Neo Neo - 1 year ago 203
ASP.NET (C#) Question

Ajaxupload.js how to pass query param to ashx file

Hi i have been trying to pass a param to my ashx page for ages

Thank you in advance

I'm currently using this setup


its using

jQuery there is a plugin from Andris Valums you

code sample

<script type="text/javascript">
$(function () {
var customerID = getURLParameter("id");
new AjaxUpload('#UploadButton', {
action: 'UploadHandler.ashx',
data: { "customerID":"44455" },
onComplete: function (file, response) {

$('#UploadStatus').html("<div class=success>file has been uploaded sucessfully</div>");
onSubmit: function (file, ext) {
if (!(ext && /^(jpg|png)$/i.test(ext))) {
alert('Invalid File Format.');
return false;


html side

<input type="button" id="UploadButton" class="btnReg charcoal" value="Upload Image" />

ashx side

public void ProcessRequest(HttpContext context)
folderPath = HttpContext.Current.Server.MapPath("DownloadedFiles");
customerID = context.Request.QueryString["customerID"];

//Uploaded File Deletion
if (context.Request.QueryString.Count > 0)
string filePath = folderPath + "//" + context.Request.QueryString[0].ToString();
deleteIMG(filePath, context.Request.QueryString[0].ToString());
//File Upload
//check if directory exist if not create one
var ext = Path.GetExtension(context.Request.Files[0].FileName);
var fileName = Path.GetFileName(context.Request.Files[0].FileName);

if (context.Request.Files[0].FileName.LastIndexOf("\\") != -1)
fileName = context.Request.Files[0].FileName.Remove(0, context.Request.Files[0].FileName.LastIndexOf("\\")).ToLower();

fileName = GetUniqueFileName(fileName, HttpContext.Current.Server.MapPath("DownloadedFiles/"), ext).ToLower();

string location = HttpContext.Current.Server.MapPath("DownloadedFiles/") + fileName + ext;

context.Response.Write(fileName + ext);


Answer Source

it has been a while since i used it, but i think it does a POST and to be able to read those parameters in your handler you need to read them from

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download