Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I would like to know how to achieve the following:

Show (hidden with code behind on page load) an ASP Button, when the FileUpload ASP control has a file selected.

aspx

XML
<asp:FileUpload ID="FileUpload1" runat="server" onchange="showButton()"/>
                       <p><asp:Button ID="Button1" runat="server"  Text="Upload File" />&nbsp;</p>



When FileUpload1 has a file selected the onchange should fire
(Button 1 stays hidden and does not show)

Javascript:

XML
<script type ="text/javascript" >
          function showButton() {
              document.getElementById('<%=Button1.ClientID%>').style.visibility = "visible";
          }
</script>


but this does not work.

Please let me know what I am doing wrong.

(should Button1.Visible=true; be used in codebehind instead, if so , how in the aspx file do you tell it to do so?)
Posted
Updated 11-Jan-13 19:14pm
v2

Try this

ASP.NET
<asp:fileupload id="fileupload1" runat="server" onchange="showButton()" xmlns:asp="#unknown" />
<asp:button id="btnUpload" runat="server" text="Upload" style="display:none" xmlns:asp="#unknown" />


JavaScript
<script type ="text/javascript" >
        function showButton() {
            document.getElementById("<%=btnUpload.ClientID%>").style.display = "";
        }
    </script>
 
Share this answer
 
Use

if (FileUpload1.hasfile==true)
{

// Your Statement//////////////
}
 
Share this answer
 
Comments
Member 12915803 2-Feb-17 2:07am    
i am getting error when i do this step any other solution for this.

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