【发布时间】:2010-09-18 06:20:55
【问题描述】:
只是想知道是否有人看过 C# .net 应用程序的任何可用进度条。我的应用程序大约需要 20-60 秒才能加载,我希望在用户等待时向他们显示进度条。我看到了this one,但示例站点似乎不起作用,这并不能激发信心。
【问题讨论】:
标签: asp.net progress-bar pageload
只是想知道是否有人看过 C# .net 应用程序的任何可用进度条。我的应用程序大约需要 20-60 秒才能加载,我希望在用户等待时向他们显示进度条。我看到了this one,但示例站点似乎不起作用,这并不能激发信心。
【问题讨论】:
标签: asp.net progress-bar pageload
我会查看这篇博文 - 似乎是个不错的方法。我自己没有测试过...
http://mattberseth.com/blog/2008/05/aspnet_ajax_progress_bar_contr.html
【讨论】:
您可以使用AJAX UpdateProgress control。
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdateProgress runat="server" id="PageUpdateProgress">
<ProgressTemplate>
Loading...
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel runat="server" id="Panel">
<ContentTemplate>
<asp:Button runat="server" id="UpdateButton" onclick="UpdateButton_Click" text="Update" />
</ContentTemplate>
</asp:UpdatePanel>
如果您想要动画,只需将动画 .gif 弹出到“ProgressTemplate”中即可。
【讨论】:
在你需要编写的 aspx 页面中,我添加了一些你自己需要定义的 CSS 类,这些代码将帮助你
<asp:Panel ID="ProgressIndicatorPanel" runat="server" Style="display: none" CssClass="modalPopup">
<div id="ProgressDiv" class="progressStyle">
<ul class="ProgressStyleTable" style="list-style:none;height:60px">
<li style="position:static;float:left;margin-top:0.5em;margin-left:0.5em">
<asp:Image ID="ProgressImage" runat="server" SkinID="ProgressImage" />
</li>
<li style="position:static;float:left;margin-top:0.5em;margin-left:0.5em;margin-right:0.5em">
<span id="ProgressTextTableCell"> Loading, please wait... </span>
</li>
</ul>
</div>
</asp:Panel>
定义一个函数说 ProgressIndicator 如下
var ProgressIndicator = function (progPrefix) {
var divId = 'ProgressDiv';
var textId = 'ProgressTextTableCell';
var progressCss = "progressStyle";
if (progPrefix != null) {
divId = progPrefix + divId;
textId = progPrefix + textId;
}
this.Start = function (textString) {
if (textString) {
$('#' + textId).text(textString);
}
else {
$('#' + textId).text('Loading, please wait...');
}
this.Center();
//$('#' + divId).show();
var modalPopupBehavior = $find('ProgressModalPopupBehaviour');
if (modalPopupBehavior != null) modalPopupBehavior.show();
}
this.Center = function () {
var viewportWidth = jQuery(window).width();
var viewportHeight = jQuery(window).height();
var progressDiv = $("#" + divId);
var elWidth = progressDiv.width();
var elHeight = progressDiv.height();
progressDiv.css({ top: ((viewportHeight / 2) - (elHeight / 2)) + $(window).scrollTop(),
left: ((viewportWidth / 2) - (elWidth / 2)) + $(window).scrollLeft(), visibility: 'visible'
});
}
this.Stop = function () {
//$("#" + divId).hide();
var modalPopupBehavior = $find('ProgressModalPopupBehaviour');
if (modalPopupBehavior != null) modalPopupBehavior.hide();
}
};
给出的示例包含一个带模态的进度指示器,即当进度指示器运行时,它会禁用在屏幕上执行的其他操作。如果不需要,可以删除模态部分。
【讨论】: