首页 新闻 会员 周边 捐助

AsyncFileUpload上传后立即显示图片问题

0
悬赏园豆:30 [已关闭问题]

环境:VS2010+AjaxControlToolKits4

页面上有一个AsyncFileUpload和一个Image服务器控件,当点击AsyncFileUpload的上传按钮成功上传图片后,Image中的图像没有改变。代码如下:

<asp:Image ID="ImgPhoto" runat="server" />
 <asp:AsyncFileUpload
OnUploadedComplete="AsyncFileUpload1_UploadedComplete"
runat="server" ID="AsyncFileUpload1" Width="400px" />

 

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadSex();
if (Request.QueryString["id"] == null)
{
TxtID.Text
= string.Empty;
BtnResetPassword.Visible
= false;
TxtName.Text
= string.Empty;
CmbSex.SelectedIndex
= 0;
ImgPhoto.ImageUrl
= "~/Images/DefaultPhoto.jpg";
TxtIDCode.Text
= string.Empty;
TxtMobile.Text
= string.Empty;
TxtEmail.Text
= string.Empty;
TxtOther.Text
= string.Empty;
TxtEntryTime.Text
= DateTime.Today.ToString("yyyy-MM-dd");
TxtDimissionTime.Text
= string.Empty;
TxtRemark.Text
= string.Empty;
BtnSubmit.Text
= "创建新用户";
}
else
{
string userid = Server.UrlDecode(Request.QueryString["id"]);
User user
= FPS.Common.User.GetItemByID(userid);
if (user == default(User))
{
Response.Write(
"对不起,您要修改的用户不存在!");
Response.End();
}
else
{
if (user.ID == Request.Cookies["UserID"].Value || user.ID.ToLower() == "admin")
{
Response.Write(
"对不起,您不能修改自己或管理员用户!");
Response.End();
}
TxtID.Text
= user.ID;
BtnResetPassword.Visible
= true;
TxtName.Text
= user.Name;
CmbSex.SelectedValue
= ((int)user.Sex).ToString();
ImgPhoto.ImageUrl
= "~/Core/LoadPhoto.aspx?userid=" + Server.UrlEncode(user.ID);
TxtIDCode.Text
= user.IDCode;
TxtMobile.Text
= user.Mobile;
TxtEmail.Text
= user.Email;
TxtOther.Text
= user.Other;
TxtEntryTime.Text
= user.EntryTime.ToString("yyyy-MM-dd");
if (user.DimissionTime.ToString("yyyy-MM-dd") == DateTime.MaxValue.ToString("yyyy-MM-dd"))
TxtDimissionTime.Text
= string.Empty;
else
TxtDimissionTime.Text
= user.DimissionTime.ToString("yyyy-MM-dd");
TxtRemark.Text
= user.Remark;
BtnSubmit.Text
= "保存修改";
}
}
}
}

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string imgpath = MapPath("~/Images/TempPhoto/") + Request.UserHostAddress + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + Path.GetExtension(e.filename);
string imgurl = imgpath.Replace(MapPath("~/Images/TempPhoto/"), "../Images/TempPhoto/");
AsyncFileUpload1.SaveAs(imgpath);
ScriptManager.RegisterClientScriptBlock(AsyncFileUpload1, AsyncFileUpload1.GetType(),
"img", "top.document.getElementById('" + ImgPhoto.ClientID + "').src='" + imgurl + "';", true);
}

请求大家帮助!

问题补充: 图像上传是成功的,但上传后没有回传,看起来ScriptManager.RegisterClientScriptBlock没有被执行
新的开始的主页 新的开始 | 小虾三级 | 园豆:679
提问于:2010-08-08 14:34
< >
分享
其他回答(1)
0

1,你先检查下你的图片是否上传到了服务器的目录;

2,客户端是否从正确的地址读取了img文件;

Launcher | 园豆:45050 (高人七级) | 2010-08-09 09:31
0

刚刚做到这个地方。。。 就是AsyncFileUpload1.SaveAs(imgpath);这句前后的其他语句都不会执行。怎么办呢

丁小贝 | 园豆:127 (初学一级) | 2011-11-10 17:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册