(vs2015 asp.net c#)使用fileupload控件上传图片,然后用image控件显示不了这个图片。
A页面:<asp:FileUploadID="load_img"runat="server"/><inputname="btn_save"type="button"val...
A页面:
<asp:FileUpload ID="load_img" runat="server" />
<input name="btn_save" type="button" value="保存" runat="server" onserverclick="btn_save_ServerClick" />
protected void btn_save_ServerClick(object sender, EventArgs e)
{
load_img.PostedFile.SaveAs(Server.MapPath("~/img/headimg/" + load_img.PostedFile.FileName));
}
B页面:
<asp:Image ID="img_headimg" runat="server" />
protected void Page_Load(object sender, EventArgs e)
{
img_headimg.ImageUrl = Server.MapPath("../img/headimg/1.png");
} 展开
<asp:FileUpload ID="load_img" runat="server" />
<input name="btn_save" type="button" value="保存" runat="server" onserverclick="btn_save_ServerClick" />
protected void btn_save_ServerClick(object sender, EventArgs e)
{
load_img.PostedFile.SaveAs(Server.MapPath("~/img/headimg/" + load_img.PostedFile.FileName));
}
B页面:
<asp:Image ID="img_headimg" runat="server" />
protected void Page_Load(object sender, EventArgs e)
{
img_headimg.ImageUrl = Server.MapPath("../img/headimg/1.png");
} 展开
2017-04-29
展开全部
img_headimg.ImageUrl = Server.MapPath("../img/headimg/1.png");
修改为
img_headimg.ImageUrl = "../img/headimg/1.png";
Server.MapPath是把虚拟地址映射为服务器实际地址。保存时,是保存到实际地址。
但是显示时,显示的虚拟地址。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询