Click here to Skip to main content
16,013,548 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am building a file uploading site ,in which if user select same file twice then i want to clear that value by javascript,
how can i change html file control's path to null.

thanks & Regards
Posted

You can clear upload file value using following:

JavaScript
document.getElementById('<%=fluUpload.ClientID%>').value='';
 
Share this answer
 
Comments
pawantiwari52 8-Nov-11 3:50am    
try this by yourself this is not working due to security reasons.
call floowing javascript function with ConrolID as parameter
C#
<script type="text/javascript"> 
function clearFileInput( id )
{
   var elem = document.getElementById( id );
   elem.parentNode.innerHTML = "";
}
</script>
 
Share this answer
 
Hi,

I tried some code for your requirement.Try this
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script language ="javascript" >
        function f1() {
            document.getElementById("fileupload1").parentElement.innerHTML = "<input type =\"file\" id=\"fileupload1\"  />";
      }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="divid" runat="server">
    <input type ="file" id="fileupload1"  />
    </div>
     
     <input type ="button" value="change" onclick ="f1()" />
        <asp:button id="Button1" runat="server" text="Button" onclientclick="f1()" onclick="Button1_Click" xmlns:asp="#unknown" />
   

    </div>
    </form>
</body>
</html>


I hope It can works for you also.

I searched alot but i don't find correct solution because.

If we change file type input tags it leads to some security breaches .

finally I tried this code .I hope you understood what I said

If you use Jquery Then you can check user uploaded files in server side.

All the Best
 
Share this answer
 

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