在asp.net的图像控制中,如何在将上传的图像保存到数据库之前预览它

本文关键字:图像 数据库 保存 控制 net asp | 更新日期: 2023-09-27 18:29:57

我允许用户上传图像。一旦用户上传图像,相应的图像就应该在图像控制中显示(类似于图像的预览)。这应该在不点击任何按钮的情况下完成

<td align="right" valign="top" class="heading">Photo: </td>
<td>
    <asp:Image ID="Image1" runat="server" /><br />
    <asp:FileUpload ID="FileUpload1" runat="server"/>
</td>

在asp.net的图像控制中,如何在将上传的图像保存到数据库之前预览它

由于您一直在要求完整的代码,而我不知道它看起来是什么样子,因此出现了一段带有大量假设的代码。。。

public void UploadImage(object sender, EventArgs e)
{
    //here you upload your image to a predefined Path and save it...
    File image = FileUpload1.getFile();// don't know how to handle it, haven't used it b4
    image.Save(path); //path is your savepath, even if its temporary
    Image1.ImageUrl = path.ToUrl();
    //alternatively do the following:
    Image1.ImageUrl = FileInfo(image).getFullPath();
    //in general you need to update controls before they show what they got so:
    Image1.Update(); / Image1.Refresh();
}

我最近和你们有同样的要求。。。我使用了AjaxFileUploader而不是普通的FileUpload控件。。和图像处理程序。。这帮助我实现了它。

上传前预览图像