图像未在图像控制中显示 [英] image is not showing in image control
本文介绍了图像未在图像控制中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在上传图片并存储在图片文件夹中但是当我按下按钮时图片iz不显示。图像保存但没有显示在图像控件中...
请帮助我
i am uploading an image and store in images folder but picture iz not display when i press button.image save but not showing in image control...
please help mee
protected void Button2_Click(object sender, EventArgs e)
{
StartUpLoad();
}
private void StartUpLoad() {
//get the file name of the posted image
string imgName = FileUpload1.FileName;
//sets the image path
string imgPath = "Images/" + imgName;
//get the size in bytes that
int imgSize = FileUpload1.PostedFile.ContentLength;
//validates the posted file before saving
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
// 10240 KB means 10MB, You can change the value based on your requirement
if (FileUpload1.PostedFile.ContentLength > 10240) {
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);
}
else
{
//then save it to the Folder
FileUpload1.SaveAs(Server.MapPath(imgPath));
Image1.ImageUrl = "~/images/" + imgPath;
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);
}
}
}
推荐答案
使用
Use
Image1.ImageUrl = "~/images/" + imgName;
的地方
at the place of
Image1.ImageUrl = "~/images/" + imgPath;
如果你使用上面的代码你的图像变成〜/ images / images / imagename ..hope你得到的点。添加相同的文件夹名称twise。
if you use above code ur imageurl becomes ~/images/images/imagename ..hope ur are getting point.ur adding same folder name twise.
嗨...
试试这个,可能对你有所帮助。
Image1.ImageUrl =imgPath;
Image1.Databind();
谢谢你。
Hi...
try this, may help ful to u.
Image1.ImageUrl = "imgPath";
Image1.Databind();
thank u.
这篇关于图像未在图像控制中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文