直接使用FileUpload,服务端是无法找到上传文件的。前面有篇文章介绍了解决方法,但是那种解决方法就使得UpdatePanel变得没有任何意义,也失去了使用它的初衷,先可以采用以下办法。

1:新建主页面Default.aspx
      在适当的位置,放置一个上传附件的UpdatePanel区域

updatepanel中不能使用fileupload的弥补方法 <atlas:UpdatePanel ID="up_attachment" Mode="Conditional" runat="server">
updatepanel中不能使用fileupload的弥补方法                
<ContentTemplate>
updatepanel中不能使用fileupload的弥补方法                        
<asp:Image ID="img_photo" runat="server" Height="64" ImageUrl="~/images/anonymous.gif"
updatepanel中不能使用fileupload的弥补方法                            Width
="64" /><br />
updatepanel中不能使用fileupload的弥补方法                        
<input type="hidden" runat="server" id="hi_src" name="hi_src" value="~/images/anonymous.gif" />
updatepanel中不能使用fileupload的弥补方法                   
<iframe id="file" name="file" src="attachment.aspx"></iframe>
updatepanel中不能使用fileupload的弥补方法                
</ContentTemplate>
updatepanel中不能使用fileupload的弥补方法
</atlas:UpdatePanel>

 2:新建上传文件的页面attachment.aspx,然后放上FileUpload控件

updatepanel中不能使用fileupload的弥补方法<div>
updatepanel中不能使用fileupload的弥补方法    
<asp:FileUpload ID="FileUpload1" runat="server" />
updatepanel中不能使用fileupload的弥补方法          
<asp:Button ID="Button1" runat="server" Text="OK" OnClick="Button1_Click" />
updatepanel中不能使用fileupload的弥补方法
</div>

3:在attachment.aspx里面,上传文件之后调用主页面的js:

updatepanel中不能使用fileupload的弥补方法protected void Button1_Click(object sender, EventArgs e)
  }

4:Default.aspx主页面里面增加这个函数,处理返回值
用js改变图片路径为新上传的路径,然后服务器端获的隐藏字段的值,即为新上传图片路径
上传页面时不能获得js更改后的image控件的属性值,所以添加一个隐藏字段。。。

updatepanel中不能使用fileupload的弥补方法 <script type="text/javascript">
updatepanel中不能使用fileupload的弥补方法     
function callBack(fileName)
script>

 

相关文章:

  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2022-02-28
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
相关资源
相似解决方案