简体   繁体   English

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

[英]how to preview uploaded image before saving it in database in image control in asp.net

I am allowing the user to upload the image. 我允许用户上传图像。 as soon as user uploads the image the respective image should get displayed in image control(similar to the preview of image). 用户上传图像后,相应的图像应立即显示在图像控件中(类似于图像预览)。 this should be done without clicking any button 无需单击任何按钮即可完成此操作

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

As you have been asking for complete code and i have no idea what it looks like here comes a piece of code with lots of assumptions... 正如您一直在要求完整的代码一样,我不知道它是什么样的,这里有一段带有很多假设的代码...

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();
}

I recently had same requirement as you ... I used AjaxFileUploader instead of normal FileUpload control .. and a Image Handler .. This helped me in achiecving it.. 我最近和您有相同的要求。。。我使用AjaxFileUploader而不是常规的FileUpload控件..和图像处理程序..这帮助我实现了它。

Preview Image before uploading 上传前预览图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM