本文介绍了图像已保存,但图像标记仍未刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我有一个图片标签和一个文件上传器上传文件。工作正常。有时用户需要更改已经上传的文件。它也可以正常工作。但问题是即使在上传新图像后,它也会被保存,但早期的图像仍然会显示在图片标记上并且不会刷新。任何帮助都会非常感激。谢谢提前。 我尝试过: < tr> < td align =left>选择文件< / td> < td style =padding-left:5px; padding-right:5px;>:< / td> < td align =left> < asp:FileUpload ID =FileUpload1runat =serverclass =txtboxAll/> < / td> < / tr> < / table> < / td> < / tr> < tr> < td align =center> < asp:Button ID =but_uploadfilerunat =serverValidationGroup =FirstTabIndex =16 CssClass =btnAllText =Uploadonclick =but_uploadfile_Click/> ; < asp:按钮ID =btn_Close01runat =serverValidationGroup =FirstTabIndex =17 CssClass =btnAllText =Close/> < / td> < / tr> protected void but_uploadfile_Click(object sender,EventArgs e ) { queryusrid = Request.QueryString [cid]。ToString(); string oldfilename1 = Path.GetFileName(FileUpload1.FileName); // FileInfo file = new FileInfo(FileUpload1.FileName); //// var sizeInBytes = file.Length; //位图img =新位图(FileUpload1.FileName); // var imageHeight = img.Height; // var imageWidth = img.Width; System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream); int height = img.Height; int width = img.Width; if(oldfilename1 ==) { Alert.Show(请选择要上传的文件); 返回; } 其他 { string gid2 = lbl_gid.Text; string ext = Path.GetExtension(FileUpload1.FileName); if(ext ==.jpg|| ext ==.JPG|| ext ==。jpeg|| ext ==.JPEG) { // if(height> = 180&& height< = 250&& width> = 200&& width< = 250) if(width == 200&& ; height == 230) { string FileExist = objcon.GetDataReadervalue(从IN005_01选择IN005_01_01,其中IN005_01 ='+ gid2 +'和IN005_01_07 ='照片',价值); if(FileExist ==Not Found) { string serpath1 = Server.MapPath(〜/ Registeration / ProfilePics /); string newfileid1 = GenerateFileID(); FileUpload1.SaveAs(serpath1 + newfileid1 + ext); string newfileid4 = newfileid1 + ext; bool ret3 = objcon.Modify(插入IN005_01(IN005_01_01,IN005_01_02,IN005_01_03,IN005_01_06,IN005_01_07,IN005_01)值('+ newfileid1 +','+ newfileid4 +','+ oldfilename1 +','sumhr','photo','+ gid2 +')); DataList1.DataBind(); UpdatePanel7.Update(); } 其他 {字符串文件名= objcon.GetDataReadervalue(从IN005_01选择IN005_01_02,其中IN005_01 ='+ gid2 +'和IN005_01_07 ='照片',价值); string filenameetn = objcon.GetDataReadervalue(从IN005_01中选择IN005_01_01,其中IN005_01 ='+ gid2 +'和IN005_01_07 ='photo',value); string path = Server.MapPath(〜)+\\Registeration+\\ProfilePics+\\+ filename; if(System.IO.File.Exists(path)) { System.IO.File.Delete(path); string serpath1 = Server.MapPath(〜/ Registeration / ProfilePics /); string newfileid1 = filenameetn; FileUpload1.SaveAs(serpath1 + newfileid1 + ext); string newfileid4 = newfileid1 + ext; bool ret3 = objcon.Modify(更新IN005_01设置IN005_01_02 ='+ newfileid4 +',IN005_01_03 ='+ oldfilename1 +',IN005_01_06 ='auto'其中IN005_01_01 ='+ filenameetn +' ); //grd_InsEdit.DataBind(); DataList1.DataBind(); UpdatePanel7.Update(); } } } 其他 { Alert.Show(图片大小应宽*高 - (200 * 230px) ); 返回; } } 其他 { Alert.Show(请上传任何jpg,png,jpeg文件); 返回; } } } 解决方案 Hi All,I have an image tag and a fileuploader to upload file.It works fine .Sometimes the user need to change the already uploaded file.It also works fine .But the problem is that even after uploading new image ,it is saved ,but the earlier image is still showing on image tag and is not refreshed.Any help will be really appreciated .Thanks in Advance.What I have tried:<tr> <td align="left">Choose file </td> <td style="padding-left:5px; padding-right:5px;">:</td> <td align="left"> <asp:FileUpload ID="FileUpload1" runat="server" class="txtboxAll" /> </td> </tr> </table> </td> </tr> <tr> <td align="center"> <asp:Button ID="but_uploadfile" runat="server" ValidationGroup="First" TabIndex="16" CssClass="btnAll" Text="Upload" onclick="but_uploadfile_Click" /> <asp:Button ID="btn_Close01" runat="server" ValidationGroup="First" TabIndex="17" CssClass="btnAll" Text="Close" /> </td> </tr>protected void but_uploadfile_Click(object sender, EventArgs e) { queryusrid = Request.QueryString["cid"].ToString(); string oldfilename1 = Path.GetFileName(FileUpload1.FileName); //FileInfo file = new FileInfo(FileUpload1.FileName); ////var sizeInBytes = file.Length; //Bitmap img = new Bitmap(FileUpload1.FileName); //var imageHeight = img.Height; //var imageWidth = img.Width; System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream); int height = img.Height; int width = img.Width; if (oldfilename1 == "") { Alert.Show("Please select a file to upload"); return; } else { string gid2 = lbl_gid.Text; string ext = Path.GetExtension(FileUpload1.FileName); if (ext == ".jpg" || ext == ".JPG" || ext == ".jpeg" || ext == ".JPEG") { //if (height >= 180 && height <= 250 && width >= 200 && width <= 250) if (width == 200 && height == 230) { string FileExist = objcon.GetDataReadervalue("select IN005_01_01 from IN005_01 where IN005_01='" + gid2 + "' and IN005_01_07='photo'", "value"); if (FileExist == "Not Found") { string serpath1 = Server.MapPath("~/Registeration/ProfilePics/"); string newfileid1 = GenerateFileID(); FileUpload1.SaveAs(serpath1 + newfileid1 + ext); string newfileid4 = newfileid1 + ext; bool ret3 = objcon.Modify("insert into IN005_01(IN005_01_01,IN005_01_02,IN005_01_03,IN005_01_06,IN005_01_07,IN005_01)Values('" + newfileid1 + "','" + newfileid4 + "','" + oldfilename1 + "','sumhr','photo','" + gid2 + "')"); DataList1.DataBind(); UpdatePanel7.Update(); } else { string filename = objcon.GetDataReadervalue("select IN005_01_02 from IN005_01 where IN005_01='" + gid2 + "' and IN005_01_07='photo'", "value"); string filenameetn = objcon.GetDataReadervalue("select IN005_01_01 from IN005_01 where IN005_01='" + gid2 + "' and IN005_01_07='photo'", "value"); string path = Server.MapPath("~") + "\\Registeration" + "\\ProfilePics" + "\\" + filename; if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); string serpath1 = Server.MapPath("~/Registeration/ProfilePics/"); string newfileid1 = filenameetn; FileUpload1.SaveAs(serpath1 + newfileid1 + ext); string newfileid4 = newfileid1 + ext; bool ret3 = objcon.Modify("update IN005_01 set IN005_01_02='" + newfileid4 + "',IN005_01_03='" + oldfilename1 + "',IN005_01_06='auto' where IN005_01_01='" + filenameetn + "'"); //grd_InsEdit.DataBind(); DataList1.DataBind(); UpdatePanel7.Update(); } } } else { Alert.Show("Image size should Width*Height-(200*230px)"); return; } } else { Alert.Show("Please upload any jpg,png,jpeg files"); return; } } } 解决方案 这篇关于图像已保存,但图像标记仍未刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-26 16:37