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 anAJAXfile 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 likeAJAXrequest. We will see about this in future code snippets.
在updatepanel面板中使用fileupload上传图片
最新推荐文章于 2019-08-01 16:18:17 发布
本文介绍在ASP.NET中如何使UpdatePanel内的FileUpload控件通过标准回发实现文件上传,而非异步回发,并提供了一个使用示例。此外还提到了一种模拟AJAX文件上传的方法,即通过iframe来实现。
1363

被折叠的 条评论
为什么被折叠?



