我在ASP.NET页面中有一个数据转发器。它加载了很多东西,用了4到5秒钟来显示图像。我无法页面或获取我需要显示所有数据的项目的一部分,所以我需要加载消息或gif,但我该怎么做?任何人都可以帮助我吗?
由于
答案 0 :(得分:1)
如果您的方案不是ajax(通过链接点击重定向经典表单回发或浏览器) 我会在重定向/回发之前将动画gif插入到html布局中(显示隐藏的div或类似的东西)。 AFAIK这种方法会对旧日浏览器产生问题(动画将被冻结)
另一种方法称为page-processor?。浏览器被重定向到中间页面,该页面在加载请求的页面时显示动画。
您还可以从服务器发送javascript代码(Response.Write / Response.Flush),它将为您当前的页面设置动画。
我还建议阻止/隐藏UI控件,例如“发送表单”,如果服务器响应时间太长,则拒绝不耐烦的用户点击两次。
答案 1 :(得分:0)
使用iframe。基本上,您可以在iframe中打开一个运行缓慢的页面,并使用iframe引发的事件来显示加载图像。
<script type="text/javascript">
var t;
//on iframe state change display or hide the loader tag
function readyStateChanged(state)
{
if (state == 'complete' || state == 4 || state == '4' || state == 'Complete')
{
//hide the loader
document.getElementById('loader').style.display = 'none';
clearTimeout(t);
} else
{
//diaplay the loader
document.getElementById('loader').style.display = '';
//hide the loader if the iframe never loads
t = setTimeout("hideLoader()", 5000);
}
}
//hide the loading tag
function hideLoader()
{
document.getElementById('loader').style.display = 'none';
clearTimeout(t);
}
</script>
<div id="loader" style="display: none;"><img />loading...</div>
<iframe id="frameX" src="your_page.aspx" width="100%" height="400px" onload="hideLoader();" onreadystatechange="readyStateChanged(this.readyState);" ></iframe>