c# - 文件上传后更新处理进度

标签 c# asp.net asp.net-ajax updatepanel progressdialog

我有一个带有两个上传控件和多个文本字段的网络表单。 当按下按钮时,文件将被上传,然后被处理。 上传不需要时间,但处理需要时间。 我知道我无法在更新面板中使用上传控件,因此我无法弄清楚如何使用更新进度控件来显示我的进度。

我的包含有效 updateprogress 控件的页面如下:

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DynamicLayout="true">
            <ProgressTemplate>
                <div class="LOADING">
                    Your data is being processed<br />
                    <br />
                    <img src="/images/loading.gif" /><br />
                    <br />
                    Please wait...
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <div class="addFixture">
            <asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="fixture" runat="server" />
            <label>
                Type
                <asp:DropDownList ID="ddlType" runat="server" AppendDataBoundItems="true">
                    <asp:ListItem Text=""></asp:ListItem>
                </asp:DropDownList>
                <label>
                    Date
                </label>
                <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
                <label>
                    Name 1</label>
                <asp:TextBox ID="txtName1" runat="server"></asp:TextBox>
                <label>
                    Name 2
                    <asp:TextBox ID="txtName2" runat="server"></asp:TextBox>
                    <label>
                        First XML File</label>
                    <asp:FileUpload ID="firstFileUp" runat="server" />
                    <br />
                    <label>
                        Second Xml File</label>
                    <asp:FileUpload ID="secondFileUp" runat="server" />
                    <br />
                    <br />
                    <asp:Button ID="SubmitButton"  runat="server" CausesValidation="true" Text="Submit" OnClick="SubmitButton_Click" />
                    <asp:Label ID="ErrorMessageLabel" runat="server" EnableTheming="false"></asp:Label>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

我已经搜索过这个,但人们似乎试图获取文件上传的进度而不是处理的进度。

有人可以帮忙吗?

最佳答案

删除 UpdatePanel,因为您无法在其中使用 FileUpload 控件。 使用以下值添加到 SubmitButton OnClientClick 属性:OnClientClick="showProgress()" 还要在页面上添加下面的 javascript 函数:

function showProgress() {
     var updateProgress = $get("<%= UpdateProgress1.ClientID %>");
     updateProgress.style.display = "block";
}

顺便说一句,考虑使用一些异步文件上传控件,例如 Ajax Control Toolkit 库中的控件

关于c# - 文件上传后更新处理进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7585140/

相关文章:

asp.net - 将 asp.net 网站迁移到 linux?

c# - MVC Ajax.beginform 自定义确认对话

C# double.TryParse with InvariantCulture 返回意外结果

c# - 返回 Stream 的方法是如何实现的?

c# - 处理asp.net页面中的多个表单标签?

asp.net - 两个外键引用相同的主键

javascript - 在 ajax 调用之前调用 return 语句

c# - Web 浏览器中的 Microsoft Office Word

javascript - Javascript 和 c# 之间的 Xamarin iOS 通信

c# - 检测是否安装了 WIF 运行时的最佳方法