ASP.NET Ajax 显示 UpdateProgress 控件最短时间

发布于 2024-08-05 14:22:49 字数 435 浏览 4 评论 0原文

有时我的 ajax 请求太快,以至于用户没有意识到进行了 ajax 调用。所以我想强制 UpdateProgress 控件显示最短的时间,即使 ajax 请求已经完成。

例如:

John 浏览网站,ajax 调用需要 2 秒才能完成。我只希望 UpdateProgress 控件显示那 2 秒。

Mary 也浏览该网站,但 ajax 调用需要 > 0.5秒。所以我想显示 UpdateProgress 控件至少 1 整秒。

有人对如何做到这一点有任何想法吗?

编辑

我发现Telerik提供的AjaxLoadingPanel控件具有此功能。它有一个名为 MinDisplayTime 的属性,可以完成此操作。如果知道如何使用标准(免费)asp.net ajax 控件来完成此操作,那就太好了。

谢谢

Sometimes my ajax request is so fast that the user does not realize a ajax call was made. So I would like to force the UpdateProgress control to display for a minimum about of time, even if the ajax request has finsihed.

For example:

John browses the site and the ajax call takes 2 seconds to complete. I only want the UpdateProgress control to display for those 2 seconds.

Mary also browses the site but the ajax call takes > 0.5 seconds. So I want to display the UpdateProgress control for at least 1 full second.

Does anybody have any ideas on how to do this?

Edit

I have discovered that the AjaxLoadingPanel control offered by Telerik has this ability. It has a property called MinDisplayTime that does this very thing. It would be nice to know how to do this using the standard (Free) asp.net ajax controls.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉梦枕江山 2024-08-12 14:22:49

我在 Intranet 站点上工作时遇到了同样的问题,其中 UpdatePanel 内容更改得如此之快,以至于我无法在不进行调试或检查数据库的情况下判断是否发生了更新。

我解决这个问题的方法是让 UpdatePanel 像以前一样做它的事情,但使用 UpdatePanelAnimationExtender 短暂地闪烁背景颜色的变化,例如,在淡出恢复正常之前,为用户提供某个动作已经发生的印象。如果这种情况发生得很快,比如 0.3 秒,并且选择了适当的“动作”颜色,那么这可能会非常有效。

<ajaxToolkit:UpdatePanelAnimationExtender ID="myUpdatePanelExtender" runat="server" TargetControlID="myUpdatePanel">
     <Animations>
        <OnUpdating> ... </OnUpdating>
        <OnUpdated> ... </OnUpdated>
    </Animations>
</ajaxToolkit:UpdatePanelAnimationExtender>

您需要获得 AJAX Control Toolkit,但如果您正在执行 Asp.Net AJAX 工作,那么如果您还没有的话,最好拥有它。

有关在 标记等中放置的内容,请参阅 Asp.Net Ajax Control Toolkit 站点页面 '使用动画'。

I had the same problem working on an intranet site where the UpdatePanel contents changed so quickly that I couldn't tell if an update had happened without debugging, or checking the database.

The way I tackled this problem was to let the UpdatePanel do its thing as before, but use an UpdatePanelAnimationExtender to briefly flash a change of background colour, for example, before fading back to normal, giving the user the impression that an action has happened. If this happens quickly, say 0.3 of a second, and an appropriate 'action' colour is chosen, this can be very effective.

<ajaxToolkit:UpdatePanelAnimationExtender ID="myUpdatePanelExtender" runat="server" TargetControlID="myUpdatePanel">
     <Animations>
        <OnUpdating> ... </OnUpdating>
        <OnUpdated> ... </OnUpdated>
    </Animations>
</ajaxToolkit:UpdatePanelAnimationExtender>

You'll need to get the AJAX Control Toolkit, but if you're doing Asp.Net AJAX work, you'll be better off having it, if you don't already.

For what to place within the <OnUpdating> tag etc., see the Asp.Net Ajax Control Toolkit site page 'Using Animations'.

救赎№ 2024-08-12 14:22:49
protected void Button1_Click(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(3000);
    Label1.Text = DateTime.Now.ToString();
}

http://www.asp.net/Ajax/Documentation/Live/教程/ProgrammingUpdateProgress.aspx

protected void Button1_Click(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(3000);
    Label1.Text = DateTime.Now.ToString();
}

http://www.asp.net/Ajax/Documentation/Live/tutorials/ProgrammingUpdateProgress.aspx

踏月而来 2024-08-12 14:22:49

您可以通过跟踪服务器端代码执行所需的时间来解决后者(或者通过测量ajax执行时间可能更好,但这更棘手),

想法是这样的

long startTime = System.DateTime.Now.Ticks;
//this process can take some time, especially when executed for the first time
//it gets data and binds it to a control
FetchData();
//if this takes not enough time, add an extra second to allow the UpdateProgress to display
if (TimeSpan.FromTicks(DateTime.Now.Ticks - startTime).TotalSeconds < 1)
            System.Threading.Thread.Sleep(1000);

you could work around the latter by keeping track of the time your server side code takes to execute (or perhaps even better by measuring the ajax execution time, but that's more tricky)

the idea is this

long startTime = System.DateTime.Now.Ticks;
//this process can take some time, especially when executed for the first time
//it gets data and binds it to a control
FetchData();
//if this takes not enough time, add an extra second to allow the UpdateProgress to display
if (TimeSpan.FromTicks(DateTime.Now.Ticks - startTime).TotalSeconds < 1)
            System.Threading.Thread.Sleep(1000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文