在updatepanel面板中使用fileupload上传图片
2011-02-04 01:44
423 查看
By default, FileUpload control will not work inside an UpdatePanel control for uploading files using Asynchronous postback. This is because, the file uploading and file manipulations is restricted by default in client side for security reasons. Hence it is not possible to upload files using asynchronous postback in UpdatePanel.
To upload files inside UpdatePanel control we need to rely upon a standard postback i.e. we need to set the button that is uploading the file to be PostBack trigger instead of AsyncPostBack trigger. This will initiate a normal postback whenever we click the upload button and it is possible to upload the file.
Refer the below code for clear understanding,
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="fuUpload" runat="server" />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
protected void btnUpload_Click(object sender, EventArgs e)
{
string filename = System.IO.Path.GetFileName(fuUpload.FileName);
fuUpload.SaveAs("C:\temp" + filename);
}
To simulate an AJAX file upload we can use iframes. In this approach, the page that is contained in the iframe will contain the FileUpload control and it will be posted with a normal postback to the server and hence provides a feeling like AJAX request. We will see about this in future code snippets.
相关文章推荐
- 在updatepanel面板中使用fileupload上传图片
- 使用UpdatePanel时FileUpload失效的问题!【FileUpload上传文件失败】
- 在UpdatePanel上使用FileUpload上传文件 (asp.net C#)
- 在UpdatePanel上使用FileUpload上传文件(转载)
- 在UpdatePanel上使用FileUpload上传文件(转)
- 在UpdatePanel上使用FileUpload上传文件
- 在UpdatePanel上使用FileUpload上传文件
- 在UpdatePanel上使用FileUpload上传文件
- 使用UpdatePanel时FileUpload失效的问题!【FileUpload上传文件失败】
- UpdatePanel内使用FileUpload上传…
- 使用UpdatePanel时FileUpload失效的问题!【FileUpload上传文件失败】
- VS2005中使用FileUpload控件上传图片并自动生成缩略图
- 使用FileUpload控件上传图片并自动生成缩略图、自动生成带文字和图片的水印图
- 解决Ajax的updatepanel控件不能使用fileupload的问题
- 使用FileUpload控件上传图片并自动生成缩略图、带文字和图片的水印图
- 牛腩购物18 : 添加商品页面2 。泛型List<T>的使用,linq 的使用, 如何在 DropDownList 里面绑定二级分类(运用linq),fileupload和图片控件的配合使用用来上传图片,try catch
- asp.net在ie7中使用FileUpload上传前预览图片
- 使用FileUpload控件上传图片并自动生成缩略图、自动生成带文字和图片的水印图
- asp.net在ie7中使用FileUpload上传前预览图片
- 使用FileUpload控件上传图片并自动生成缩略图、自动生成带文字和图片的水印图(转)