如何预览上传的图像,然后将其保存在asp.net的图像控件中的数据库中

时间:2013-09-03 10:20:04

标签: c# asp.net

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

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

2 个答案:

答案 0 :(得分: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();
}

答案 1 :(得分:0)

我最近和你有同样的要求...我使用了AjaxFileUploader而不是普通的FileUpload控件..还有一个Image Handler ..这有助于我实现它..

Preview Image before uploading