如何在其他页面的图像控件中显示fileupload控件的所选图像 [英] How to display fileupload control's selected image in image control on other page

查看:64
本文介绍了如何在其他页面的图像控件中显示fileupload控件的所选图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Web表单,一个是WebForm1.aspx,另一个是WebForm2.aspx。



在WebForm1上,我把FileUpload Control从系统和Button控件中获取图像转移到WebForm2页面。

现在我想在Image Control中显示这个图像,当我单击WebForm1上的按钮时,它在WebForm2上。那么我怎么能做到这一点。

I have two web forms one WebForm1.aspx and second WebForm2.aspx.

On WebForm1 i put FileUpload Control to get image from the system and a Button control to transfer to WebForm2 page.
Now i want to show this image in Image Control, which is on WebForm2 when i click the button on WebForm1. So how can i achive this.

推荐答案

当你点击 WebForm1 中的按钮时,将该图像保存在文件系统中数据库

然后重定向到第二页 WebForm2



WebForm2 页面加载中,从文件数据库检索图像并将其绑定到asp 图像控制
When you click Button in WebForm1, save that image either in File System or Database.
Then redirect to the second page that is WebForm2.

In WebForm2 Page Load, retrieve image from File or Database and bind that to a asp Image Control.


正如Tadit所提到的,决定如何保存图像,文件系统或数据库。



然后使用Querystring在Navigation(Response.Redirect)中传递imagepath或(在保存在数据库中的情况下为imageid),并在Webform2中检索查询字符串值。 imagepath保存在文件系统中或插入imageid,如果在db中显示在Image控件中。
As Tadit mentioned, decide how to save the image , File system or DB.

Then use Querystring to pass imagepath or( imageid in case saved in database) in the Navigation ( Response.Redirect) and in Webform2 retrieve the querystring value . imagepath in case saved in File System or inserted imageid if in db to display in Image control.


我自己解决了这个问题,谢谢你们的支持。

这是我的代码:



WebForm1.aspx.cs

I have solved this myself, thank you guys for your support.
Here is my Code :

WebForm1.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
        {
            
            string fileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
            FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/" + fileName));
            Session["image"] = fileName;
            Response.Redirect("WebForm2.aspx");
        }



WebForm2.aspx.cs


WebForm2.aspx.cs

protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["image"] != null)
            {
                string fileName = Session["image"].ToString();
                img1.ImageUrl = "~/images/" + fileName;
            }
        }


这篇关于如何在其他页面的图像控件中显示fileupload控件的所选图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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