首页 新闻 搜索 专区 学院

使用AsyncFileUpload控件实现上传图片功能

1
悬赏园豆:20 [待解决问题]

请教个问题,我在使用AsyncFileUpload控件实现上传图片后立即显示刚上传图片的功能,我一开始的时候让image控件显示个初始图片,让上传成功后显示新上传的图片,出现的问题就是图片上传到了目标文件夹,但image控件却还显示的是初始图片,这是怎么回事?
我上传服务器的代码如下所示:
 protected void AsyncFileUpload1_UploadedComplete1(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
 {
  if (AsyncFileUpload1.HasFile)
  {
  AsyncFileUpload1.SaveAs(Server.MapPath("../upload") + "\\" + criterion_ID + "." + type);
  this.Image_new.ImageUrl = "../upload/" + criterion_ID + "." + type;
  url_1 = "../upload/" + criterion_ID + "." + type;
  ScriptManager.RegisterClientScriptBlock(this.AsyncFileUpload1, this.AsyncFileUpload1.GetType (), "img", "top.document.getElementById('" + this.Image_new.ClientID + "').src='" + url_1 + "';", true);
}
}

问题补充: 还有一个问题就是,AsyncFileUpload主要是有两方法,一个是onuploadedcomplete方法,它是用来上传图片的,代码如上;再一个就是浏览器端OnClientUploadComplete方法,它主要用来显示我上传的图片的,我要问的是,这两个方法有没有可传递参数的方法,因为我在onuploadedcomplete上传图片后,想把图片的ID传到OnClientUploadComplete中根据ID提取图片进行显示????
spook1125的主页 spook1125 | 初学一级 | 园豆:100
提问于:2010-12-22 15:24
< >
分享
所有回答(1)
0

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUploadExample.aspx.cs" Inherits="FileUploadExample" %>

前台页面:

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form runat="server">
 <asp:ToolkitScriptManager runat="server" >
 </asp:ToolkitScriptManager>
    <div>
    
    <asp:AsyncFileUpload runat="server"
   onuploadedcomplete="AsyncFileUpload1_UploadedComplete" Throbber />
  <asp:Image runat="server" />
 </div>
    </form>
</body>
</html>

 

后台代码中:

 protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) {
  Thread.Sleep(5000);
  string strFileName = this.AsyncFileUpload1.FileName;
  FileInfo fi = new FileInfo(strFileName);
  string strName = fi.Name;
  string extension = fi.Extension;
  string tagName = "~/Upload\\" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + extension;
  this.AsyncFileUpload1.SaveAs(Server.MapPath(tagName));
 }

 

欢乐 | 园豆:332 (菜鸟二级) | 2011-12-09 15:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册