|
直接使用FileUpload,服务端是无法找到上传文件的。
如何实现 1:新建主页面Default.aspx 在适当的位置,放置一个上传附件的UpdatePanel区域 <asp:Image ID="img_photo" runat="server" Height="64" ImageUrl="~/images/anonymous.gif" Width="64" /><br /> <input type="hidden" runat="server" >> protected void Button1_Click(object sender, EventArgs e)
4:Default.aspx主页面里面增加这个函数,处理返回值{ string fileFullPath = fu_photo.PostedFile.FileName; string fileName = fileFullPath.Substring(fileFullPath.LastIndexOf('\\') + 1); string fileSavePath = "../Photos/" + fileName; fu_photo.PostedFile.SaveAs(Server.MapPath(fileSavePath)); Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "photoscript", "window.top.callBack('" + fileSavePath + "');", true); 用js改变图片路径为新上传的路径,然后服务器端获的隐藏字段的值,即为新上传图片路径 上传页面时不能获得js更改后的image控件的属性值,所以添加一个隐藏字段。。。 function callBack(fileName) { document.getElementById('<%=img_photo.ClientID %>').src=fileName; document.getElementById('<%=hi_src.ClientID %>').value=fileName; } |
相关文章: