[英]How to work with ImageButton in code behind in C#
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (FileUpload1.HasFile)
{
string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string path = Server.MapPath("~//Images//" + FileName);
FileUpload1.SaveAs(path);
string imagepathsource = path;
string imagepathdest = @"D:\\" + Session["brandname"].ToString() + "\\" + Seasonfolders.SelectedItem.Text + "\\" + stylefolders.SelectedItem.Text + "\\Images\\" + FileName;
File.Move(imagepathsource, imagepathdest);
uploadedimage.ImageUrl = "D://" + Session["brandname"].ToString() + "//" + Seasonfolders.SelectedItem.Text + "//" + stylefolders.SelectedItem.Text + "//Images//" + FileName;
}
}
uploadedimage is a ImageButton where I need to display the image using imageurl with that link. uploadedimage是一个ImageButton,我需要使用带有该链接的imageurl来显示图像。 The image is not displaying and no error.. I could see when the above code gets execute the page is getting refreshed?
图像没有显示,没有错误..我可以看到上面的代码执行时页面正在刷新? What code can be added in this ??
可以添加什么代码?
ImageUrl
needs an URL. ImageUrl
需要一个URL。
So instead of assigning it with a local file name on disk, use something like this (where ~
stands for 'application root folder': 因此,不要在磁盘上使用本地文件名分配它,而是使用类似这样的东西(其中
~
代表'应用程序根文件夹':
uploadedimage.ImageUrl = "~/Images/yourImage.png"
You have to supply it with: 你必须提供:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.