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.

4 Answers 4

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());

Sign up to request clarification or add additional context in comments.

Comments

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

you're missing '

1 Comment

I'm sure, I am not missing close quote in my code. Sorry for typo in the post question.
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.)

1 Comment

Actually I use $("[id$='FileUpload1']").val(""), which does not work
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.