如何在其他页面的图像控件中显示fileupload控件的所选图像

编程入门 行业动态 更新时间:2024-10-05 11:14:36
本文介绍了如何在其他页面的图像控件中显示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控件的所选图像

本文发布于:2023-11-03 04:44:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554267.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   图像   所选   页面   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!