Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET
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.
<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)
<script type ="text/javascript" >
          function showButton() {
              document.getElementById('<%=Button1.ClientID%>').style.visibility = "visible";
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 20:13pm
AU Jase624
Edited 11-Jan-13 20:14pm
Rate this: bad
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 = "";
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

if (FileUpload1.hasfile==true)
// Your Statement//////////////

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

  Print Answers RSS
0 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 329
2 CPallini 260
3 DamithSL 214
4 Maciej Los 197
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115

Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | 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