开发者

Automatically submitting a form when an upload file is chosen

I have a HTML page with the following input tag开发者_运维百科:

...
<input type="file" id="browseContactImageButton" />
... 

Clicking the button on the page results in Open File Dialog. If I want to do the actual uploading, I need another button to click (submit), because this input file button is used just to provide the path to the file.

Is it possible to click the browse button, select the file and to start the uploading function immediately after the file has been chosen? If yes, could anyone provide the code snippet? Thanks.


If you want the form to submit after the user has made their selection, then simply add

<input type="file" onchange="this.form.submit();" ..... >


I had the same requirement.

I figured out to use onchange event of fileupload control to fire c# method.

But I'm getting FileUpload1.HasFile property always 'False' and file name was not set yet.

My markup:

<asp:FileUpload ID="FileUpload1" runat="server" ClientIDMode="AutoID" 
                        ViewStateMode="Enabled" onchange="UploadImage();"/>

any suggessions?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜