【发布时间】:2020-03-30 21:26:14
【问题描述】:
我有一个 ASP 应用程序,它有一个页面,用户可以在其中选择不同的选项,然后用于生成 Excel 报告。通过单击按钮触发报告处理。我想在单击按钮时添加一条加载消息,以向用户显示报告正在运行,因为根据选择的选项,生成文件可能需要几分钟时间。
我的问题是报告处理代码在后面的代码中运行,我无法找到一种方法让 ascx.vb 上的按钮单击功能触发页面更新,同时运行处理代码并下载报告。我已经尝试过异步,但我认为我没有正确使用它。
我还是一个初学者,所以很难在网上学习很多例子。任何有关如何实现此目的的建议将不胜感激。
这是我的按钮点击代码:
Private Async Sub DownloadExcelReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DownloadExcelReport.Click
DownloadInProgress.Visible = True
Await Task.Run(Sub()
ProcessExcelReport() 'long running sub (not an async function).
End Sub)
End Sub
这是 UI 表单的(精简的)HTML 代码
<header class="header bg-light bg-gradient b-b pull-in" style="margin-top:-10px; margin-bottom: 10px;">
<p class="h4">Report Download</p>
</header>
<section class="hbox wrapper">
<section class="panel panel-default">
<div class="panel-top-border"></div>
<asp:Panel ID="DownloadInProgress" runat="server" Visible="false">
<div class="alert alert-info">
<i class="fa fa-info-sign"></i><strong>Notice!</strong> Report Download is in progress. Report will download when complete.
</div>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" style="padding-left: 20px; padding-bottom: 20px; padding-right:20px; padding-top:20px;">
<div>
<asp:Label ID="lbl2" runat="server" class="newlwoverridelabel">Scope</asp:Label>
<asp:DropDownList runat="server" AutoPostBack="true" ID="ScopeCombo" OnSelectedIndexChanged="ScopeCombo_SelectedIndexChanged" CssClass="form-control m-b" Width="200px" style="display:inline-block">
</asp:DropDownList>
<asp:Label ID="Label2" runat="server" class="newlwoverridelabel">Report Name</asp:Label>
<asp:DropDownList ID="reportSelect" AutoPostBack="true" runat="server" CssClass="form-control m-b" Width="400px" style="display:inline-block" OnSelectedIndexChanged="reportSelect_SelectedIndexChanged">
</asp:DropDownList>
</div>
<div style='margin-left:5px;margin-bottom:5px;'>
<asp:Button runat="server" Text="Download Excel Report" ID="DownloadExcelReport" />
</div>
</asp:Panel>
</section>
</section>
【问题讨论】:
标签: asp.net vb.net visual-studio user-interface async-await