我正在尝试将该图像路径绑定到图像上传控件(页面刷新后),该控件已保存在会话中以及视图状态中,但缺少某些内容并且无法处理该内容...会话和视图状态正确路径存储但没有绑定。只有这件事需要解决...
获取Unable的异常,将'System.String'类型的对象强制转换为'System.Web.UI.WebControls.FileUpload'。
fuUploadLogo是我的图片上传控件,第二行不能将会话中的路径绑定到fileupload控件。
asp:FileUpload ID =“fuUploadLogo”runat =“server”
if (Session["PicturePath1"] == null)
{
Session["PicturePath1"] = ViewState["PicturePath"].ToString();
}
else if (Session["PicturePath1"] != null)
{
fuUploadLogo = (FileUpload)Session["PicturePath1"];
}
答案 0 :(得分:1)
我认为您应该添加图像控件来查看图片,例如:
在aspx中,添加
<VideoView
android:id="@+id/videoView2"
android:layout_width="250dp"
android:layout_height="300dp"
/>
在aspx.cs中
<asp:Image ID="Image1" runat="server" />
答案 1 :(得分:0)
请尝试以下
<asp:FileUpload ID="fileupload1" runat="server"></asp:FileUpload>
//If first time page is submitted and we have file in FileUpload control but not in session
// Store the values to SEssion Object
if (Session["PicturePath"] == null && FileUpload1.HasFile)
{
Session["PicturePath"] = FileUpload1.PostedFile.FileName;
}
// Next time submit and Session has values but FileUpload is Blank
// Return the values from session to FileUpload
else if (Session["PicturePath"] != null && (! FileUpload1.HasFile))
{
FileUpload1 = (FileUpload) Session["PicturePath"];
}
// Now there could be another sictution when Session has File but user want to change the file
// In this case we have to change the file in session object
else if (FileUpload1.HasFile)
{
Session["PicturePath"] = FileUpload1.PostedFile.FileName;
}