环境:VS2010+AjaxControlToolKits4
页面上有一个AsyncFileUpload和一个Image服务器控件,当点击AsyncFileUpload的上传按钮成功上传图片后,Image中的图像没有改变。代码如下:
<asp:Image ID="ImgPhoto" runat="server" /><asp:AsyncFileUploadOnUploadedComplete="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);
}
请求大家帮助!
1,你先检查下你的图片是否上传到了服务器的目录;
2,客户端是否从正确的地址读取了img文件;
刚刚做到这个地方。。。 就是AsyncFileUpload1.SaveAs(imgpath);这句前后的其他语句都不会执行。怎么办呢