Click here to Skip to main content
15,908,626 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,
As for my requirement i want to paste the values from textbox to fileupload(browse control) using javascript.But there is no chance to paste the value from textbox that controls are disabled in fileupload(browser-Ie8).Please anybody solve my problem.
Please check my code.
XML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"  runat="server">
    <title>Untitled Page</title>
       <%--Scenario1--%>
    <script language="javascript" type="text/javascript">
          function filepath(txtval) {
         document.getElementById("txtpath").value= txtval.value;
//         Clear Fileupload
         var textpath=document.getElementsByName('<%=UploadFile.UniqueID%>')[0];
         textpath.value="";
         var textpath2= textpath.cloneNode(false);
         textpath2.onchange= textpath.onchange;
         textpath.parentNode.replaceChild(textpath2,textpath);
                  }
 // right click and control click disabled
//           function enablecopypaste(ex){
//            var message = "Cntrl key/ Right Click Option Enabled";
//            // Condition to check mouse right click / Ctrl key press
//            if (ex.which == 0 || ex.button == 1) {
//            alert(message);
//            return false;
//            }
//            }
    </script>
    <%--for size
    <style type="text/css" >
    .size1{width:627px}
    </style>--%>

</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <%--<asp:FileUpload ID="UploadFile" runat="server" onchange="filepath(this)" CssClass="size1" Width="627px"/><br />--%>
        <asp:FileUpload ID="UploadFile" runat="server" OnChange="filepath(this)" Width="610px" /><br />
        <asp:TextBox ID="txtpath" runat="server" Width="521px">
       <%-- onKeyDown="return enablecopypaste(event)" onMouseDown="return enablecopypaste(event)">--%>
        <br />
    </div>
    </form>

</body>
</html>
Posted
v5

1 solution

Please go through the answer Fileupload should not be empty after Click button[^], where it says...


You can get that fileupload control text but you can't set value due to security reasons

so take some other textbox set value to that like
C#
txtFileUploaderValue.Text = FileUploader.Value

if your missing value then store in view state variable and set to textbox
 
Share this answer
 
v2
Comments
Hari Krishna Prasad Inakoti 27-Sep-12 2:12am    
Hi Tadit Dash,
Please check my code
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<%--Scenario1--%>
<script language="javascript" type="text/javascript">
function filepath(txtval) {
document.getElementById("txtpath").value= txtval.value;
// Clear Fileupload
var textpath=document.getElementsByName('<%=UploadFile.UniqueID%>')[0];
textpath.value="";
var textpath2= textpath.cloneNode(false);
textpath2.onchange= textpath.onchange;
textpath.parentNode.replaceChild(textpath2,textpath);
}
// right click and control click disabled
// function enablecopypaste(ex){
// var message = "Cntrl key/ Right Click Option Enabled";
// // Condition to check mouse right click / Ctrl key press
// if (ex.which == 0 || ex.button == 1) {
// alert(message);
// return false;
// }
// }
</script>
<%--for size
<style type="text/css" >
.size1{width:627px}
</style>--%>

</head>
<body>
<form id="form1" runat="server">
<div>
<%--<asp:FileUpload ID="UploadFile" runat="server" onchange="filepath(this)" CssClass="size1" Width="627px"/><br />--%>
<asp:FileUpload ID="UploadFile" runat="server" OnChange="filepath(this)" Width="610px" /><br />
<asp:TextBox ID="txtpath" runat="server" Width="521px">
<%-- onKeyDown="return enablecopypaste(event)" onMouseDown="return enablecopypaste(event)">--%>
<br />
</div>
</form>

</body>
</html>
Yes the line where you are getting the FileUploader
var textpath=document.getElementsByName('<%=UploadFile.UniqueID%>')[0];
is not working, that's why you are not able to do the task...
Instead try this...

function ClearBrowseContent(control)
{
var browse = document.getElementById(control);
var newbrowse = browse.cloneNode(false);
browse.parentNode.replaceChild(newbrowse ,browse);
}
Please accept the answer, if it has helped you. It will be easier for others to find the answer and you will also be awarded with some points...

Thanks a lot.
Hari Krishna Prasad Inakoti 1-Oct-12 1:41am    
Hi Tadit,
it is also not working.
What is the problem you are facing ?

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