本文介绍了如何在图像按钮上单击上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个图像按钮,我想在cimage上传一个文件。 我的图片按钮和上传者标记是 < asp:FileUpload ID =fplUploadExcelrunat =serverStyle =position:relative; visibility: hidden; height: 20px; ClientIDMode =静态/> < ; asp:ImageButton ID =ImageButton1runat =serverWidth =150pxStyle =position:relative; ImageUrl =〜/ Images / Uploadingimage.jpg/> And即时得到的载点击页面负荷follws是 ImageButton1.Attributes [ 点击] =的String.Format(的document.getElementById( '{0}' ).click();,fplUploadExcel.ClientID); 但是请不要打电话给上传功能请告诉我我将如何做到这一点 我的上传功能是 受保护 void uploadExcel() { if (fplUploadExcel .HasFile) { // 串excelfilepath = fplUploadExcel.PostedFile.FileName; // if(fplUploadExcel.PostedFile.FileName ==EmployeeSheet.xlsx) // { string filename = Server.MapPath( @ 〜\\Excel \\); fplUploadExcel.PostedFile.SaveAs(filename + fplUploadExcel.FileName); string excelfilepath = Server.MapPath( 〜\\Excel \\ + fplUploadExcel.FileName); importdatafromexcel(excelfilepath); SelectUpdaterecordFeromExcel(); 解决方案 我得到了你的问题,如果你想打电话给你需要一个服务器端功能使用onclick如果你想使用clientide函数使用onclientclick 请试试这个以满足你的要求 '预郎= CSS> < ASP:ImageButton的 ID = ImageButton1 RUNAT = 服务器 WIDTH = 150像素 类型=位置:相对;ImageUrl =〜/ Images / Uploadingimage.jpgonclick =uploadExcel()/> 并替换你的表格标签用这个 < form id =form1enctype =multipart / form-datarunat =server> 一切顺利:) I have an image button and i want to upload an file on cimage click.my image button and uploader markup is<asp:FileUpload ID="fplUploadExcel" runat="server" Style="position: relative; visibility: hidden; height: 20px;" ClientIDMode="Static" /><asp:ImageButton ID="ImageButton1" runat="server" Width="150px" Style="position: relative;" ImageUrl="~/Images/Uploadingimage.jpg" />And i m getting click of uploader as follws on page load isImageButton1.Attributes["onclick"] = string.Format("document.getElementById('{0}').click();", fplUploadExcel.ClientID);but don't hoe to call the upload function please tell me how will i do this my upload function is protected void uploadExcel() { if (fplUploadExcel.HasFile) { // string excelfilepath = fplUploadExcel.PostedFile.FileName; //if (fplUploadExcel.PostedFile.FileName == "EmployeeSheet.xlsx") //{ string filename = Server.MapPath(@"~\\Excel\\"); fplUploadExcel.PostedFile.SaveAs(filename + fplUploadExcel.FileName); string excelfilepath = Server.MapPath("~\\Excel\\" + fplUploadExcel.FileName); importdatafromexcel(excelfilepath); SelectUpdaterecordFeromExcel(); 解决方案 I got your problem if you want to call a serverside function you need to use onclick and if you want to use clientside function use "onclientclick"pls try this for your requirement<asp:ImageButton ID="ImageButton1" runat="server" Width="150px" Style="position: relative;"ImageUrl="~/Images/Uploadingimage.jpg" onclick="uploadExcel()"/>And replace your form tag with this<form id="form1" enctype="multipart/form-data" runat="server">All the best:) 这篇关于如何在图像按钮上单击上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-25 17:04