Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I have three file upload controls and i am uploading 3 different images into all in pop up,

but when i clear the value of single fileupload control it clears the all other also,

so i need a code which clear a single control at a time,

i used Java Script code and c# code also but both behaving same as it clears the all controls

I have used this type of codes...
JavaScript
function ClearFileUpload1() {
var fil = document.getElementById("file1");
fil.select();
n = fil.createTextRange();
n.execCommand('delete');
fil.focus();
}


c#
C#
fileupload1.dispose();
fileupload1.Attributes.Clear();
fileupload1=new FileUpload();
Posted
Updated 2-Jan-15 22:33pm
v3
Comments
DamithSL 3-Jan-15 3:34am    
update the question with your code
Amit Jadli 3-Jan-15 3:44am    
function ClearFileUpload1() {
var fil = document.getElementById("file1");
fil.select();
n = fil.createTextRange();
n.execCommand('delete');
fil.focus();
}


c#

fileupload1.dispose();
fileupload1.Attributes.Clear();
fileupload1=new FileUpload();

i got the solution for this problem

i m using now java script code
<script type="text/javascript">
function fnClearFileSelection(objFileUpload) {
objFileUpload.value = "";
objFileUpload.focus();
return false;
}
</script>

and the file upload is looking like this

<asp:FileUpload ID="fuPhoto" runat="server" ClientIDMode="Static"/>


and the Clear button looks like this

<asp:LinkButton ID="lnkClear" runat="Server" OnClientClick="return fnClearFileSelection(FuPhoto);"></asp:LinkButton>
 
Share this answer
 
v4
Dude if you are going to server side to clear your control then you are doing wrong as you know if you are going to server side the whole page gets refresh so you have to do it using client side.
 
Share this answer
 
Comments
Amit Jadli 5-Jan-15 0:22am    
I had used Server side and client side both,

but both behaving the same as it clears all the controls,

and i m using server side controls
MohitMunjal 5-Jan-15 4:13am    
Please Add your .aspx and your .aspx.cs code so that i can analyse the code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900