我正在打开 Telerik RadWindowManager 弹出窗口。有一个很长的数据库操作要执行。在加载期间,即大约 35-40 秒,目前,我继续等待,直到该过程结束。
有什么办法可以先加载设计并显示一个加载器/进度条通知用户等待...实际上当网速很慢时问题会变得更糟...
任何建议....
我正在打开 Telerik RadWindowManager 弹出窗口。有一个很长的数据库操作要执行。在加载期间,即大约 35-40 秒,目前,我继续等待,直到该过程结束。
有什么办法可以先加载设计并显示一个加载器/进度条通知用户等待...实际上当网速很慢时问题会变得更糟...
任何建议....
这里我有一个很好的例子。见这里演示。
.aspx 文件:
<telerik:RadScriptManager id="ScriptManager1" runat="server" />
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"/>
<p>
Press the submit button in order to start monitoring custom progress
</p>
<asp:button ID="buttonSubmit" runat="server" Text="Submit" OnClick="buttonSubmit_Click" CssClass="RadUploadButton" />
<telerik:RadProgressManager id="Radprogressmanager1" runat="server" />
<telerik:RadProgressArea id="RadProgressArea1" runat="server" />
aspx.cs 文件:
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
//Do not display SelectedFilesCount progress indicator.
RadProgressArea1.ProgressIndicators &= ~ProgressIndicators.SelectedFilesCount;
}
RadProgressArea1.Localization.Uploaded = "Total Progress";
RadProgressArea1.Localization.UploadedFiles = "Progress";
RadProgressArea1.Localization.CurrentFileName = "Custom progress in action: ";
}
protected void buttonSubmit_Click(object sender, System.EventArgs e)
{
UpdateProgressContext();
}
private void UpdateProgressContext()
{
const int total = 100;
RadProgressContext progress = RadProgressContext.Current;
progress.Speed = "N/A";
for (int i = 0; i < total; i++)
{
progress.PrimaryTotal = 1;
progress.PrimaryValue = 1;
progress.PrimaryPercent = 100;
progress.SecondaryTotal = total;
progress.SecondaryValue = i;
progress.SecondaryPercent = i;
progress.CurrentOperationText = "Step " + i.ToString();
if (!Response.IsClientConnected)
{
//Cancel button was clicked or the browser was closed, so stop processing
break;
}
progress.TimeEstimated = (total - i) * 100;
//Stall the current thread for 0.1 seconds
System.Threading.Thread.Sleep(100);
}
}
现在应该更容易集成您的代码。
编辑:要在 PageLoad 中设置 RadProgressArea 后触发您的数据库操作,您需要在第一页加载后进行一些 ajax 调用(所以我只是添加RadAjaxManager
到 ascx 文件上部)。使用此代码触发您的数据库调用:
javascript:
function pageLoad(sender, eventArgs) {
if (!eventArgs.get_isPartialLoad()) {
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("StartDBOperation");
}
}
ascx.cs 文件:
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
if (e.Argument == "StartDBOperation")
{
// Start DB operation here..
}
}
仍然是下面的替代方案...但不是解决方案
我可以在内容加载时显示如下加载面板
<div id="loading" style=" width: 100px; height: 50px; display: none;
text-align: center; margin: auto;">
loading...
</div>
<asp:Button ID="RadButton1" runat="server"
Text="RadButton1" OnClientClick="openRadWnd(); return false;" />
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
<Windows>
<telerik:RadWindow ID="RadWindow1" runat="server"
NavigateUrl="url" ShowContentDuringLoad="false"
OnClientShow="OnClientShow" OnClientPageLoad="OnClientPageLoad">
</telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
<script type="text/javascript">
var loadingSign = null;
var contentCell = null;
function openRadWnd() {
$find("<%=RadWindow1.ClientID %>").show();
}
function OnClientShow(sender, args) {
loadingSign = $get("loading");
contentCell = sender._contentCell;
if (contentCell && loadingSign) {
contentCell.appendChild(loadingSign);
contentCell.style.verticalAlign = "middle";
loadingSign.style.display = "";
}
}
function OnClientPageLoad(sender, args) {
if (contentCell && loadingSign) {
contentCell.removeChild(loadingSign);
contentCell.style.verticalAlign = "";
loadingSign.style.display = "none";
}
}
</script>
在客户端用 JavaScript 打开 RadWindow,通过 JavaScript 设置所需的 URL。执行不处理 RadWindow 的部分回发。如果您仅在服务器上获取 URL - 使用相同的逻辑,但最初显示加载符号,当响应完成时调用脚本再次更改 RadWINdow 的 URL。 http://www.telerik.com/help/aspnet-ajax/window-programming-opening.html http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side .html http://www.telerik.com/help/aspnet-ajax/window-programming-radwindow-methods.html