js显示等待信息

ynyn0829 2007-07-04 07:06:31
请问,我在.cs文件的page_load事件中写有如下代码
response.write("<div>");
response.write(" ");
response.write("</div>");
response.write("<script languange=javascript>");
response.write("function test(){div.innerText='Hello';}")
response.write("</script>");
response.flush();
Thread.sleep(10000);
为什么总是要等到页面全部加载后才能显示hello啊?
请问高手,为什么会这样?要如何解决呢(就用这种方式,因为我看到孟老大有段实现相同功能的代码,所以就自己这样写了下,可是总不能显示这个信息)?
...全文
657 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
YiYanXiYin 2007-07-07
  • 打赏
  • 举报
回复
flush的内容至少要有256字节。也就是只有编译产生了至少256字节的数据,才能在执行Response.Flush()以后将信息发到客户端并显示。
ynyn0829 2007-07-05
  • 打赏
  • 举报
回复
其实我知道有其它方法可以实现。只不过我仍然对我上面写的代码弄不明白。不晓的错在什么地方??也不知道为什么孟老大的代码就可以实现,关键是在什么地方??太多不明白了。

仍然非常感谢strife() ( ) 的帮助!!!结贴继续研究下!!!
strife013 2007-07-05
  • 打赏
  • 举报
回复
添加html内容(insertAdjacentHTML和insertAdjacentText)
dhtml提供了两个方法来进行添加,insertAdjacentHTML和insertAdjacentText
insertAdjacentHTML方法:在指定的地方插入html标签语句。
原型:insertAdjacentHTML(swhere,stext)
参数:
swhere:指定插入html标签语句的地方,有四种值可以用:
1.beforeBegin:插入到标签开始前
2.afterBegin:插入到标签开始标记后
3.beforeEnd:插入到标签结束标记前
4.afterEnd:插入到标签结束标记后
stext:要插入的内容
例:var sHTML="<input type=button onclick=" + "go2()" + " value='Click Me'><BR>"
var sScript='<SCRIPT DEFER>'
sScript = sScript + 'function go2(){ alert("Hello from inserted script.") }'
sScript = sScript + '</script' + '>';
ScriptDiv.insertAdjacentHTML("afterBegin",sHTML + sScript);
在html正文中加入一行:
<DIV ID="ScriptDiv"></Div>
最终变成:
<DIV ID="ScriptDiv">
<input type=button onclick=go2() value='Click Me'><BR>
<SCRIPT DEFER>
function go2(){alert("Hello from inserted sctipt.")}'
</script>
</DIV>
insertAdjacentText方法与insertAdjacentHTML方法类似,只不过只能插入纯文本,参数相同
strife013 2007-07-05
  • 打赏
  • 举报
回复
window.attachEvent('onbeforeunload',divdisplay);
然后function divdisplay(){
var sInsert="<div id='divShowWaitingMsg' style='position:absolute; display:inline; left:0px; top:0px; width:100%; height:100%; z-index:1000;BACKGROUND-COLOR: white;FILTER: Alpha(Opacity=100);'>";
sInsert+="<iframe id=frmShowWaitingMsg width='100%' height='100%' border=0 >"
sInsert1="<head><meta http-equiv='content-type' content='text/html; charset=utf-8'></head><body>"
sInsert1+="<style type=text/css>TD{COLOR: #000031; FONT-SIZE: 12px}</style>"
sInsert1+="<table width='100%' height='100%'>";
sInsert1+="<tr>";
sInsert1+="<td>";
sInsert1+="<table height=50 width=200 bgcolor=#E1E5F4 border=1 cellpadding=0 cellspacing=0 align='center' bordercolorlight='#B5BCE8' bordercolordark='#666666' style='border-collapse: collapse'>";
sInsert1+=" <tr>";
sInsert1+=" <td nowrap align='center'>数据载入中, 请稍候.... </td>";
sInsert1+=" </tr>";
sInsert1+="</table>";
sInsert1+="</td>";
sInsert1+="</tr>";
sInsert1+="</table>";
sInsert1+="</body>";
sInsert+="</iframe>";
sInsert+="</div>";
try{document.body.insertAdjacentHTML ("AfterBegin", sInsert);}catch(e){}
try{frmShowWaitingMsg.document.write (sInsert1);}catch(e){}
}
ynyn0829 2007-07-05
  • 打赏
  • 举报
回复
回楼上的,我是想不用什么控件。
我现在主要是郁闷的是,我把最开始完整的代码改了一小部分后就不能实现那个效果了。大家可以看看,我改后的也仅仅是把除掉了他的一部分代码。
从昨天搞到今天,都没有搞明白是什么原因。(比方说,改改函数名或其它的,有时候又能实现那个效果),郁闷啊 >_<!!!
稍微有点无敌 2007-07-05
  • 打赏
  • 举报
回复
哈哈,自己写当然也可以,不过这个东西我目前看到的最好的是老外写的一个控件:
DotNetBusyBox,是sf.net上的开源项目,我的项目里面也用这个东西
ynyn0829 2007-07-05
  • 打赏
  • 举报
回复
来后先顶下。
大家帮我看看下,谢谢啦~~~
ynyn0829 2007-07-05
  • 打赏
  • 举报
回复
大家帮我下,都快被搞疯了。我改成如下:
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script language=javascript>");

Response.Write("function test()");
Response.Write("{var output; output = '正在装载页面';");
Response.Write("for(var x = 0;x < 1;x++){output+='.';}mydiv.innerText = output;}");
Response.Write("mydiv.style.visibility='visible';");
Response.Write("test();");

Response.Write("</script>");
Response.Flush();
Thread.Sleep(5000);
结果就不能等等显示,把test()改成ShowWait()就又可以了。我试了它的源码,改成其它的函数名也是可以的,与函数名无关。
请问各位,到底是怎么回事啊???
iuhxq 2007-07-04
  • 打赏
  • 举报
回复
按理应该可以的





欢迎访问我的视频搜索引擎:

http://www.vzhangmen.com
happy_sky 2007-07-04
  • 打赏
  • 举报
回复
哎 看着头疼 我把格式从调了下

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write(" var dots = 0;");
Response.Write(" var dotmax = 10;");
Response.Write(" function ShowWait()");
Response.Write(" {");
Response.Write(" var output;");
Response.Write(" output = '正在装载页面';");
Response.Write(" dots++;");
Response.Write(" if( dots >= dotmax ) dots=1;");
Response.Write(" for(var x = 0;x < dots;x++)");
Response.Write(" {");
Response.Write(" output += '.';");
Response.Write(" }");
Response.Write(" mydiv.innerText = output;");
Response.Write(" }");
Response.Write(" function StartShowWait()");
Response.Write(" {");
Response.Write(" mydiv.style.visibility = 'visible'; ");
Response.Write(" window.setInterval('ShowWait()',1000);");
Response.Write(" }");
Response.Write(" function HideWait()");
Response.Write(" {");
Response.Write(" mydiv.style.visibility = 'hidden';");
Response.Write(" window.clearInterval();");
Response.Write(" }");
Response.Write(" StartShowWait();");
Response.Write("</script>");
Response.Flush();
Thread.Sleep(10000);
}
}
ynyn0829 2007-07-04
  • 打赏
  • 举报
回复
没人帮帮我啊??
dz45693 2007-07-04
  • 打赏
  • 举报
回复
ding
ynyn0829 2007-07-04
  • 打赏
  • 举报
回复
如果我在上面的代码中去掉一些,仅仅显示一个“正在装载页面”,就又向我显示的“hello”一样不行了。
ynyn0829 2007-07-04
  • 打赏
  • 举报
回复
回楼上的,应该不是那样。response.flush();实际上就是把先前已有的内容发送到客户端的。这里有孟老大的段代码。只不过我稍微改点就不能显示了。我也不知道要注意那里。希望大家帮我分析下。我不想仅仅把代码copy下。谢谢!
//*********************************
在Page_Load事件里输入: Visual C# .NET代码
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText = output;}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();
Thread.Sleep(10000);
//********************************
希望大家能够帮我看下。以上是孟大哥的代码。
YiYanXiYin 2007-07-04
  • 打赏
  • 举报
回复
第一个请求显示hello并等待一段时间,然后发送第二个请求

YiYanXiYin 2007-07-04
  • 打赏
  • 举报
回复
cs代码在服务器端执行,而显示信息在客户端
在一个请求响应的过程中,客户端不得不等到所有的服务器端代码执行完才能显示

要实现你的功能不得不分成2请求

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧