页面代码:
<asp:Panel ID="panelOne" runat="server" Visible ="false">
<asp:Image ID="ImgOne" runat="server" ImageUrl="../images/none.jpg" style="width: 120px; height: 120px" EnableViewState ="false" AlternateText="暂无图片" />
<asp:FileUpload ID="UpOne" runat="server" Height="21px" Width="180px" />
<iframe id="frameOne" visible="false" runat="server" ></iframe>
</asp:Panel>
cs中load()
if (!this.IsPostBack)
{ string oprOne = "document.getElementById('" + this.ImgOne.ClientID + "').src=document.getElementById('" + this.UpOne.ClientID + "').value;document.getElementById('" + this.frameOne.ClientID + "').InnerText=document.getElementById('" + this.ImgOne.ClientID + "').src";
this.UpOne.Attributes.Add("onchange", oprOne);
}我现在想在页面刷新的时候FileUpload 之前选择的图片路径不丢失,想用一个隐藏框架把他记下来,一直没搞定,谁帮我整哈,谢谢。
<asp:Panel ID="panelOne" runat="server" Visible ="false">
<asp:Image ID="ImgOne" runat="server" ImageUrl="../images/none.jpg" style="width: 120px; height: 120px" EnableViewState ="false" AlternateText="暂无图片" />
<asp:FileUpload ID="UpOne" runat="server" Height="21px" Width="180px" />
<iframe id="frameOne" visible="false" runat="server" ></iframe>
</asp:Panel>
cs中load()
if (!this.IsPostBack)
{ string oprOne = "document.getElementById('" + this.ImgOne.ClientID + "').src=document.getElementById('" + this.UpOne.ClientID + "').value;document.getElementById('" + this.frameOne.ClientID + "').InnerText=document.getElementById('" + this.ImgOne.ClientID + "').src";
this.UpOne.Attributes.Add("onchange", oprOne);
}我现在想在页面刷新的时候FileUpload 之前选择的图片路径不丢失,想用一个隐藏框架把他记下来,一直没搞定,谁帮我整哈,谢谢。
this.ImgTwo.ImageUrl = this.frameOne.InnerText;
但是为空,panelOne已经可见了。
if (!this.IsPostBack)
{ string oprOne = "document.getElementById('" + this.ImgOne.ClientID + "').src=document.getElementById('" + this.UpOne.ClientID + "').value;document.getElementById('" + this.frameOne.ClientID + "').InnerText=document.getElementById('" + this.ImgOne.ClientID + "').src";
this.UpOne.Attributes.Add("onchange", oprOne);
}
{
var hfFileName=document.getElementById("hfFileName");
var UpOne=document.getElementById("UpOne");
if(hfFileName && UpOne)
{alert(hfFileName.value);
//UpOne.value=hfFileName.value;
UpOne.onchange=setFileName;
}
}
function setFileName()
{
var hfFileName=document.getElementById("hfFileName");
hfFileName.value=this.value;
}
window.onload=init;
</script>
<asp:FileUpload ID="UpOne" runat="server" />
<asp:HiddenField ID="hfFileName" runat="server" />file The value, a file name, typed by the user into the control. Unlike other controls, this value is read-only. input file 的value是只读的
顶,楼主的想法很好,但实现不了, <asp:FileUpload ... 生成的 <input type="file" ...., 其value是只读的,不能设置不能修改。