从ASP.NET FileUpload控件的JavaScript加载图像 [英] Load Image with Javascript from ASP.NET FileUpload control

查看:128
本文介绍了从ASP.NET FileUpload控件的JavaScript加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图加载一个asp图像框< ASP:图片ID =imgPictureWIDTH =200HEIGHT =200=服务器/> 与用户之后的图像已使用asp.net FileUpload控件选择了一个< ASP:文件上传ID =fluPicture=服务器的OnChange =的LoadImage(THIS.VALUE imgPicture'); WIDTH =200/>

I am trying to load an asp image box <asp:Image ID="imgPicture" width="200" height="200" runat="server" /> with an image after a user has selected one using the asp.net fileupload control <asp:FileUpload ID="fluPicture" runat="server" OnChange="LoadImage(this.value, 'imgPicture');" Width="200"/>

HTML

<asp:Image ID="imgPicture" width="200" height="200" runat="server" />
<asp:FileUpload ID="fluPicture" runat="server" OnChange="LoadImage(this.value, 'imgPicture');" Width="200"/>

的JavaScript

<script type="text/javascript">
    function LoadImage(path, img) {
        imgPrev = document.images[img];
        imgPrev.src = path;
   }
</script>

图片不会在imgPicture控制负载。我也注意到,通过添加警惕JavaScript函数来提醒路径和形象,该路径是 C:\\ fakepath \\ ImageName.jpg 。我不确定为什么说fakepath。

The image will not load in the imgPicture control. Also I noticed that by adding an alert to the javascript function to alert the path and image, that the path is C:\fakepath\ImageName.jpg. I am unsure why it says fakepath.

任何帮助是AP preciated。另外请注意,这个项目背后都有一个C#code文件。

Any help is appreciated. Also note that this project has a C# code file behind it.

推荐答案

所有的输入之后,我已经改变了我的FileInput控制code到如下:

After all of your input, I have changed my FileInput control code to be as follows:

<asp:FileUpload ID="fluPicture" onchange="if (confirm('Upload ' + this.value + '?')) this.form.submit();" runat="server" Width="200"/>

我然后加入测试到Page.OnLoad事件,以确定该文件是否准备好是
上传。

I then added a test to the Page.OnLoad event to determine if the file is ready to be uploaded.

if (fluPicture.PostedFile != null && fluPicture.PostedFile.ContentLength > 0) UploadImage();

然后我允许的UploadImage()方法来上传图片,储存,然后imagebox的URL设置上传的图片的URL。

Then I allowed the UploadImage() method to upload the image, store it, and then set the url of the imagebox to the uploaded image's url.

感谢大家的帮助和投入。另外,我AP preciate jQuery的想法。在这种情况下我只是需要一些快速和肮脏来完成这项工作。

Thank you all for your help and input. Also, I appreciate the jQuery ideas. In this instance I just needed something quick and dirty to get the job done.

这篇关于从ASP.NET FileUpload控件的JavaScript加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆