4

I know to clear context of a textbox, using $('#textbox1').val(""); But how to clear context of a FileUpload control. I mean to erase the content of it's textbox. For example, I first choose a file using FileUpload control, which it shows c:\user\1.png. Now I want to clear it by using jQuery.

$('#FileUpload1').val(""); 

apprently does not work here.

Steven Zack
  • 4,984
  • 19
  • 57
  • 88

4 Answers4

3
$('#FileUpload1').val("");

won't work on ie.

document.getElementById("#FileUpload1").createTextRange().execCommand('delete');` will work on ie

or you can use
var file = document.getElementById("<%=FileUpload1.ClientID%>"); $(file).parent().html($(file).parent().html());

sav sharma
  • 31
  • 3
1
$('#FileUpload1').val(""); 

you're missing '

genesis
  • 50,477
  • 20
  • 96
  • 125
0

might try this

<input type="file" id="control"/>
<button id="clear">Clear</button>
var control = $("#control");

$("#clear").on("click", function () {
    control.replaceWith( control = control.clone( true ) );
});

http://jsfiddle.net/jonathansampson/dAQVM/

taken from here : Clearing <input type='file' /> using jQuery

Community
  • 1
  • 1
Dhaval
  • 2,801
  • 20
  • 39
0

Your FileUpload control will be rendered as a div with an input of type "file" and a client ID determined by your ClientIDMode. In many circumstances, it will be the same as your control's server-side ID.

There's an excellent explanation of how ASP.net generates client-side IDs from server-side ones here

(Or, you could just be missing a closing quote.)

Yes - that Jake.
  • 16,725
  • 14
  • 70
  • 96