我正在尝试使用 Asp.NetAjaxFileUpload
控件异步为隐藏字段分配值,但是当我访问它时,我得到空值;
<Ajax:AjaxFileUpload ID="FileUploadGaurdianPic" runat="server"
ThrobberID="myThrobber" MaximumNumberOfFiles="1"
OnUploadComplete="FileUploadGaurdianPic_UploadComplete" OnClientUploadComplete="uploadComplete" />
编码;
public string GuardianPic
{
get
{
if (ViewState["GuardianPic"] == null)
return "/Resources/Images/generic.jpg";
else
return ViewState["GuardianPic"].ToString();
}
set
{
ViewState["GuardianPic"] = value;
}
}
protected void FileUploadGaurdianPic_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string path = Server.MapPath("~/Resources/Images/temp/");
string name = String.Empty;
string storedPath = String.Empty;
if (Directory.Exists(path))
{
name = Path.GetFileName(e.FileName);
storedPath = path + name;
FileUploadGaurdianPic.SaveAs(storedPath);
GuardianPic = "/Resources/Images/temp/"+name; // assigning the value here
}
}
但是当我尝试访问它时:
string ur = GuardianPic;
我得到了属性的默认值,而不是我在上传完成事件中分配的值;