views:

180

answers:

3

Scenario: On click of a button, we dynamically create html file input (file upload) control on the page and call that file input controls Click() method. User then selects the file from the disk. There is a “Submit” button to upload the selected file.

Problem: The problem is, when clicked on “Submit” button first time, the input value from the file input control is cleared. And the request does not go to the server. When clicked second time, the request goes to server with empty file input value.

Why the first click on submit button does not send the request to server. And why it clears the file input control value?

Note: The issue is observed only when we call Click() method programmatically. If we let user to click browse, then in that case, the "Submit" does not clear the input value and sends request to server on first click itself.

Any help would be appreciated. Thanks in advance.

By the way, server side code is in asp.net and client side in java script, testing on IE.

-Somesh

A: 

This is more or less equivalent to your quey: http://stackoverflow.com/questions/1829774/jquery-simulating-a-click-on-a-input-typefile-doesnt-work-in-firefox

The thing that you are trying does not seem to be possible.

Anand Patel
A: 

I have the same problem. Were you able to find a work around this or the traditional browse button is the only way? thanks! -Tee

Tee
A: 

Can you inject some javascript from your code-behind that would call the client-side click() event on that file upload control? This would simulate the user clicking the submit button, which you know works.

Coov