如何从图像按钮浏览图像? [英] How can I browse image from image button?

查看:86
本文介绍了如何从图像按钮浏览图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用图像按钮作为系统的浏览文件,就像FileUpload Toll一样,我使用JavaScript onclick功能:



  function  chooseFile(){
document .getElementById( FileUpload1)。click();
}



和HTML:

 < ;   asp:ImageButton     ID   =  ImageButton7      runat   =  server    OnClientClick   =  chooseFile();    BorderColor   = #CCCCCC    

BorderStyle = 虚线 BorderWidth = 1px ImageUrl < span class =code-keyword> = 〜/ Webpics / picbo x.png

/ >



但它不起作用...... :(



我尝试过:



  function  chooseFile(){
document .getElementById( FileUpload1)点击();
}





和HTML:

 <   asp:ImageButton     ID   =  ImageButton7      runat   =  server    OnClientClick   =  chooseFile();    BorderColor   = #CCCCCC    

< span class =code-attribute> BorderStyle = 虚线 BorderWidth = 1px ImageUrl = 〜/ Webpics / picbox.png / > ;



但是它不起作用...... :(

解决方案

你没有解释什么不起作用,你忘了发布代码。我只是猜测fileupload.HasFile总是空的?看起来像ImageButton正在引起戏剧化。每次单击它时,都会导致PostBack并删除已发布的文件。你可以做几件事



1.用客户端控件替换服务器ImageButton控件

 <   img     src   =  / Webpics / picbox.png    onclick   =  chooseFile()    style   =  border:1px dashed #ccc;    /  >  



2.将控件包装到AJAX面板中,这是一个示例

更新面板中的文件上传 [ ^


I want to use image button as a browse files from systems just like FileUpload Toll does, i use JavaScript onclick function:

function chooseFile() {
          document.getElementById("FileUpload1").click();
      }


and HTML:

<asp:ImageButton ID="ImageButton7"  runat="server" OnClientClick="chooseFile();" BorderColor="#CCCCCC" 

                BorderStyle="Dashed" BorderWidth="1px" ImageUrl="~/Webpics/picbox.png" 

                />


But it doesn't work... :(

What I have tried:

function chooseFile() {
          document.getElementById("FileUpload1").click();
      }



and HTML:

<asp:ImageButton ID="ImageButton7"  runat="server" OnClientClick="chooseFile();" BorderColor="#CCCCCC" 

                BorderStyle="Dashed" BorderWidth="1px" ImageUrl="~/Webpics/picbox.png" />


But it does'nt work... :(

解决方案

You didn't explain what didn't work and you forgot to post the code behind. I'm just guessing the fileupload.HasFile is always empty? Look like the ImageButton is causing the drama. Every time you clicked on it, it caused a PostBack and that erased the posted files. There are couple of thing you can do

1. Replace the server ImageButton control with the client control

<img src="/Webpics/picbox.png" onclick="chooseFile()" style="border: 1px dashed #ccc;" />


2. Wrap the control into AJAX Panel, here is an example
File Upload in Update Panel[^]


这篇关于如何从图像按钮浏览图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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