使用fileupload动态创建图像控件 [英] dynamically create an image control with fileupload

查看:64
本文介绍了使用fileupload动态创建图像控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的webform(asp.net 2010)上有一个文件上传和一个按钮控制按钮.

我想要的是,只要单击按钮以上传文件(图像),它就应该动态创建一个图像控件并将imageurl设置为我刚刚上传的图像.并且应该显示图像...但是,它不起作用..请帮助我给出一个理由..以下代码:-

I have a fileupload and a button control button on my webform(asp.net 2010).

What i want is , as soon as i click on the button to upload the file(image), it should dynamically create an image control and set the imageurl to be the one which i just uploaded. And the image should be displayed...however , it is not working..please help me giving a reason..Following si the code :-

protected void Button1_Click(object sender, EventArgs e)
    {
string str=FileUpload1.FileName;
    string path=Server.MapPath("image");
        string fulpath=path + "\\" + str;
        FileUpload1.PostedFile.SaveAs(fulpath);
        Image img = new Image();
        Page.Form.Controls.Add(img);
        img.ImageUrl = Server.MapPath(str);
    }

推荐答案

可能是Server.MapPath(str)没有获得正确的路径.所以,试试看.
May be Server.MapPath(str) is not getting the correct path. So, try this.
img.ImageUrl = fulpath;




or

img.ImageUrl = FileUpload1.PostedFile;


这篇关于使用fileupload动态创建图像控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆