简体   繁体   English

在更新面板中显示带有文件上传的进度更新

[英]Show Progress Update with File Upload in Update Panel

I am developing a website in asp.net using VS2013 and C# (webforms). 我正在使用VS2013和C#(webforms)在asp.net中开发一个网站。 I have a page that accepts some user input, including an <asp:FileUpload> server control. 我有一个页面可以接受一些用户输入,包括<asp:FileUpload>服务器控件。 The entire form is inside an update panel, allowing me to display a progress update div that pops up when the user submits the form. 整个表单都位于更新面板中,这使我可以显示进度更新div,该进度更新div在用户提交表单时弹出。

I have read that having a file upload server control inside an update panel causes issues, so I am using a <asp:PostBackTrigger> to force a postback so that the upload control's .HasFile property is not always false. 我已经了解到,在更新面板中具有文件上传服务器控件会导致问题,因此我正在使用<asp:PostBackTrigger>强制回发,以便上传控件的.HasFile属性并不总是为false。

Throughout the site, when there is a delay due to DB activity, I use <asp:UpdatePanel> and <asp:UpdateProgress> to show the user that there is some activity and to protect the form from being altered or resubmitted once the user hits submit. 在整个站点中,当由于数据库活动而导致延迟时,我使用<asp:UpdatePanel><asp:UpdateProgress>向用户显示有一些活动,并保护该表单在用户点击后不会被更改或重新提交。提交。 It works fine. 工作正常。

The problem is that the <asp:PostBackTrigger> is also preventing the <asp:UpdateProgress> from appearing. 问题在于<asp:PostBackTrigger>还会阻止<asp:UpdateProgress>出现。 This leaves the form vulnerable to unwanted user input after submission, and is also a bad user experience. 这样会使表单容易在提交后遭到用户输入的干扰,并且也是不良的用户体验。 So I am in a catch22 - I cannot remove the PostBackTriggers because then the file upload control won't work, and I cannot use the UpdateProgress on submit because the PostBackTriggers prevents it from showing. 因此,我处于陷阱22 –无法删除PostBackTriggers,因为文件上传控件将无法使用,并且由于PostBackTriggers阻止了它的显示,因此我无法在提交时使用UpdateProgress。

Some code: 一些代码:

 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <%-- Some irrelevant code left out --%> <div class="row"> <div class="input-group col-sm-6"> <span class="input-group-addon" style="width: 175px; text-align: right;" id="basic-addon10">Signature</span> <asp:FileUpload ID="uplSignature" runat="server" CssClass="form-control" /> </div> <%-- Some irrelevant code left out --%> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="btnSubmit" /> </Triggers> <asp:UpdateProgress ID="UpdateProgress" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="0"> <ProgressTemplate> <div class="updateProgressMain" style="position: fixed;"> <div class="updateProgressDiv" style="position: fixed;"> <img src="Images/loader.gif" alt="" /> </div> </div> </ProgressTemplate> </asp:UpdateProgress> 

What would be the best way to resolve this? 解决此问题的最佳方法是什么?

Thanks for the help in advance. 我在这里先向您的帮助表示感谢。

EDIT - I accepted the use of the Ajax File Upload Control from the Ajax Control Toolkit as the answer because it did actually work to solve my problem. 编辑 -我接受了Ajax控件工具包中的Ajax文件上载控件的使用作为答案,因为它确实可以解决我的问题。 I am not thrilled with it because I am finding it hard to style to match the look and feel of my site - but it does work. 我对此并不感到兴奋,因为我发现很难进行样式设置以使其与网站的外观和风格相匹配-但这确实有效。 Thanks for the suggestion. 谢谢你的建议。

I would take a look at the AjaxFileUpload control that is shipped with the Ajax Control Toolkit. 我将看一下Ajax控件工具包附带的AjaxFileUpload控件。

I had a similar issue previously and remember that the ajax one worked for me. 以前我也遇到过类似的问题,请记住,ajax为我工作。

You can find some info about it here: https://ajaxcontroltoolkit.devexpress.com/AjaxFileUpload/AjaxFileUpload.aspx 您可以在这里找到有关它的一些信息: https : //ajaxcontroltoolkit.devexpress.com/AjaxFileUpload/AjaxFileUpload.aspx

To get the Ajax Control Toolkit just search for it in NuGet. 要获取Ajax Control Toolkit,只需在NuGet中进行搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM