在 Upadtepanel 中
<form id="form1" runat="server">
Fileupload 會無法正常運作
也就是說 Postback 時無法取得檔案
為了達到非同步
又希望可以有檔案上傳功能
我們可以把 Fileupload 寫在另外一頁 aspx 中
UploadPage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UploadPage.aspx.cs" Inherits="Web.UploadPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" Width="30em" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
AjaxFileUpload.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxFileUpload.aspx.cs" Inherits="Web.AjaxFileUpload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<asp:ScriptManager runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate> <div>
<iframe id="Iframe1" frameborder="0" name="I1" height="32px" width="100%" src="UploadPage.aspx"></iframe>
</div>
</form>
</ContentTemplate>
</asp:UpdatePanel>
</body>
</html>
利用 iFrame 將檔案上傳的 aspx 置入
如此一來可利用主視窗呼叫 iFrame 中的 Button Click
便可解決 FileUpload 在 UpdatePanel 中無效的問題
全站熱搜