请教个问题,我在使用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);
}
}
<%@ 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));
}