我需要上传文件。文件上传时我需要显示进度条。但当我点击updatepanel中的上传按钮时,fileupload中的文件会在我添加触发器时消失,文件将上传但进度条将不会显示 这是我的代码
<%@ Page Title="" Language="C#" MasterPageFile="~/site.Master" AutoEventWireup="true" CodeBehind="upload.aspx.cs" Inherits="fix_asset.upload" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.auto-style2 {
height: 23px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table style="margin:auto; padding-top:50px">
<tr>
<td style="font-weight: 600; font-size: large; background-color: #0000FF; border: thin solid #000000">
UPLOAD MASTER FILE
</td>
</tr>
<tr style="border: thin solid #000000; background-color: #DBD5FD;">
<td>
<table>
<tr>
<td style="width:100px">
Location
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
<td style="width:100px">
<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" OnClientClick="uploadfile()" style="width:100px" />
</td>
<td style="width:100px">
<asp:Button ID="Button2" runat="server" Text="Sampling" OnClick="Button2_Click" style="width:100px" />
</td>
</tr>
<tr>
<td colspan="4" style="text-align:center" class="auto-style2">
<asp:Label ID="lblNotification" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button4" runat="server" Text="Button" style="visibility:hidden" OnClick="Button4_Click" />
<asp:HiddenField ID="HiddenField2" runat="server" />
<br />
<hr />
<br />
</ContentTemplate>
</asp:UpdatePanel>
<table style="margin:auto; padding-top:50px; width:560px; border-collapse: collapse;">
<tr style="font-weight: 600; font-size: large; background-color: #0000FF; border: thin solid #000000">
<td colspan="3" >VLOOK UPLOAD</td>
</tr>
<tr style="border: thin solid #000000; background-color: #DBD5FD; padding:5px 5px 5px 5px">
<td>
Location
</td>
<td>
<asp:FileUpload ID="FileUpload2" runat="server" style="width:100%" />
</td>
<td>
<asp:Button ID="Button3" runat="server" style="width:100%" Text="Upload" onclick="Button3_Click" OnClientClick="uploadfile2()" />
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="lblNotification2" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
<script>
function uploadfile() {
document.getElementById('<%= HiddenField1.ClientID%>').value = document.getElementById('<%= FileUpload1.ClientID%>').value;
}
function uploadfile2() {
document.getElementById('<%= HiddenField2.ClientID%>').value = document.getElementById('<%= FileUpload2.ClientID%>').value;
}
</script>
</asp:Content>
答案 0 :(得分:0)
AJAX更新面板用于防止页面具有完整的回发。使用更新面板,我们可以进行部分页面回发。部分页面回发执行以下操作
1.提高应用程序的性能
2.减少应用程序的页面加载时间
3.减少应用程序和服务器之间的往返
4.只有网页中需要刷新的部分才能获得回发
我们知道我们可以使用文件上传控件将文件上传到服务器。但是,如果我们在更新面板中使用文件上传控件,则它不起作用。原因是文件上载控件不适用于异步回发。
将此添加到您的表单标记,然后添加触发器,如图所示
<form id="form1" runat="server" method="post" enctype="multipart/form-data" >
.....
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID = "uploadbuttonID"/>
</Triggers>
</asp:UpdatePanel>
.....
</form>
参考此链接......