如何在FileUpload选择文件时显示ASP按钮 [英] How to show an ASP Button only when FileUpload has file chosen

查看:81
本文介绍了如何在FileUpload选择文件时显示ASP按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想知道如何实现以下目标:



Show(隐藏在页面加载后面的代码)一个ASP按钮,当FileUpload ASP控件有一个文件被选中。



aspx



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>







当FileUpload1有选择onchange的文件应该点亮

(按钮1保持隐藏且不显示)



Javascript:






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>





但这不起作用。



请让我知道我做错了什么。



(应该Button1.Visible = true;在代码隐藏中使用,如果是这样,你怎么在aspx文件中告诉它这样做?)



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?)

推荐答案

试试这个



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>


使用



如果(FileUpload1.hasfile == true)

{



//你的陈述///////////// /

}
Use

if (FileUpload1.hasfile==true)
{

// Your Statement//////////////
}


这篇关于如何在FileUpload选择文件时显示ASP按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆