Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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
 
<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:
 
<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 11-Jan-13 19:13pm
AU Jase624
Edited 11-Jan-13 19:14pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this
 
<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" />
 
<script type ="text/javascript" >
        function showButton() {
            document.getElementById("<%=btnUpload.ClientID%>").style.display = "";
        }
    </script>
 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use
 
if (FileUpload1.hasfile==true)
{
 
// Your Statement//////////////
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 448
1 Sergey Alexandrovich Kryukov 290
2 PhilLenoir 95
3 Uma Shankar Patel 80
4 CB Sharma 79
0 Sergey Alexandrovich Kryukov 6,532
1 OriginalGriff 5,976
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,550


Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100