0

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

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

2 回答 2

0

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

上传前预览图像

于 2013-11-25T12:48:08.253 回答
0

正如您一直在要求完整的代码,而我不知道它是什么样子的,这里有一段带有很多假设的代码......

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();
}
于 2013-09-03T11:15:44.800 回答