Question

how do i pass arguments to generic handler (Asp.net) from javascript/jquery?

i have a generic Handler for jquery plugin (ajaxfileupload) and i need to pass some arguments from page(jquery/javascript) (Ex. Dynamic Save Path , autogenerated filename,etc...)

Was it helpful?

Solution

its Working as follow:

$.ajaxFileUpload(
{       
    url: 'MyHandler.ashx?filename=test.png&path=../test/Images'
        secureuri: false,
        fileElementId: 'fileToUpload',
        dataType: 'json',
        data: { name: 'logan', id: 'id' },
        success: function(data, status) {
            if (typeof (data.error) != 'undefined') {
                if (data.error != '') {
                    alert(data.error);
                } else {
                    alert(data.msg);
                }
            }
        },
        error: function(data, status, e) {
        alert(e);
    }
})

In The Generic Handler

public void ProcessRequest(HttpContext context)
{
    string stringParam = (string)context.Request["filename"];
}

Another Solution

var strFileName="test.png";
$.ajaxFileUpload(    
{       
    url: 'MyHandler.ashx?filename=test.png&path=../test/Images'
        secureuri: false,
        fileElementId: 'fileToUpload',
        dataType: 'json',
        data: { name: 'logan', id: 'id',filename: strFileName },
        success: function(data, status) {
            if (typeof (data.error) != 'undefined') {
                if (data.error != '') {
                    alert(data.error);

                } else {
                alert(data.msg);

                }
            }
        },
        error: function(data, status, e) {
        alert(e);
    }
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top