执行 Web 服务时在 ASP.NET 页面中显示动画 GIF

发布于 2025-01-07 10:06:00 字数 502 浏览 0 评论 0原文

我已经阅读了该网站以及 MSDN 上的许多帖子,但无法找到我正在寻找的解决方案。这是我的情况:我有一个允许用户“上传”文件的页面。该页面包含一个 asp.net fileUpload 控件。然而,它所做的只是将字节数组发送到 WSE 2.0 Web 服务。我无法改变这一点。将来可能会更新,但现在,这是我必须遵循的。

该页面有一个 gif 动画,当用户单击“提交”按钮时就会启动。并且页面应该根据Web服务调用返回的结果进行相应的更新。我能够启动 gif 并成功使用 WS。但是,当页面访问 Web 服务时,gif 文件会冻结。

然后我尝试使用单独的线程来使用 Web 服务。这会加快进程速度并且不会冻结 gif,但 Web 服务完成时页面不会更新。如果我让主线程进入睡眠状态,页面就会更新,但我又回到了上面提到的同一问题,即 gif 冻结了。

我很确定我可以使用 javascript 进行调用并以这种方式更新页面,但此时,我真的宁愿在服务器端执行此操作(如果没有其他原因,出于固执)。

有人能指出我正确的方向吗?提前致谢。

I've read many posts on this site, as well as MSDN, but can't quite find the solution I'm looking for. Here is my situation: I have a page that allows users to "upload" a file. The page includes an asp.net fileUpload control. However, all it does is send the byte array to a WSE 2.0 web service. I can't change this. This may be updated in the future, but for now, this is what I have to go with.

The page has an animated gif that starts when the user clicks the submit button. And the page should be updated accordingly based on the result returned by the web service call. I'm able to start the gif and consume the WS successfully. However, while the page is hitting the web service, the gif file freezes.

I then tried to use a separate thread to consume the web service. This speeds up the process and does not freeze the gif, but the page is not updated when the web service completes. If I put the main thread to sleep, the page updates, but I'm back to the same issue mentioned above, where the gif freezes.

I'm pretty sure I could make the call using javascript and update the page that way, but at this point, I'd really rather do it server side (out of stubbornness if nothing else).

Can someone point me in the right direction? Thanks in advance.

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

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

发布评论

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

评论(2

百变从容 2025-01-14 10:06:00

这也发生在我身上。我设法通过将 img 标签包装在 div 内并使用 通过 JavaScript 显示/隐藏 div 来解决此问题setTimeout函数。这样 GIF 就不会冻结。

示例:

<script type="text/javascript">
    function showLoadingIco() {
        setTimeout(showLoadingGif, 50);
    }
    function showLoadingGif() {
        // Using jQuery
        $('#myDiv').css('display', 'inline');
    } 
</script>

请注意,您的 HTML 代码必须如下所示:

<div id="myDiv" style="display:none">
    <img src="loading.gif" alt="Loading..." />
</div>

This has happened to me as well. I've managed to fix this by wrapping the img tag inside a div and just showing / hiding the div via JavaScript using the setTimeout function. The GIF won't freeze this way.

Example:

<script type="text/javascript">
    function showLoadingIco() {
        setTimeout(showLoadingGif, 50);
    }
    function showLoadingGif() {
        // Using jQuery
        $('#myDiv').css('display', 'inline');
    } 
</script>

Note that your HTML code must look like this:

<div id="myDiv" style="display:none">
    <img src="loading.gif" alt="Loading..." />
</div>
淡写薰衣草的香 2025-01-14 10:06:00

上传文件控件不能很好地与更新面板配合使用,所以我的猜测是您遇到了完整的回发,这就是图像停止旋转的原因。如果您没有使用更新面板(或其他一些 Ajax 平台),那么您几乎肯定会收到回发。

不过,使用 JQuery 实现异步并不是太难。查看此链接示例。

The Upload File control doesn't work well with Update Panels, so my guess is that you're running into a full postback, which is why the image stops spinning. If you're not using an Update Panel (or some other Ajax platform), you're almost definitely having a post back.

It's not too tough to pull off asynchronously with JQuery though. Check out this link for an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文