最近做的项目中遇到了这个问题,就是在用window.showModalDialog打开aspx页面时,你点击打开之后,被打开的页面,有一段时间页面主体是白色的,这样的话,有些用户就受不了了。
所以要做些改进了。1、想到了在body里onload事件,结果不行。
2、想到了Page页面事件执行顺序,Page.PreInit应该是最前面的。
就想到在此事件里写代码。

Code
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();
还别说,这还真起到一半的作用。
但还是不能解决问题。原因是啥着呢?
3、想到了IIS处理请求的方式,HTML页面肯定是最快的啦,浏览器可以直接执行。
因此就想到了用HTML页面来代替aspx页面,再在HTML页面里用个iframe,就可以解决问题了。这次,是真的解决问题了。
原来的链接变成这样的。
<a id="addnew" runat="server" href="#" style="color:Blue;cursor:hand;text-decoration:underline">新增</a>
后台代码page_load:this.addnew.Attributes.Add("onclick", "javascript:window.open('LinkNew.htm','','height=700,width=800,location=no,status=no')");
LinkNew.htm

Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>选择部门</title>
<script language="javascript" type="text/javascript">
document.onreadystatechange=function()
{
if(document.readyState=="complete")
{
document.getElementById('loading').style.display='none';
}
}
function Request(strName)
{
var strHref = window.document.location.href;
var intPos = strHref.indexOf("?");
var strRight = strHref.substr(intPos + 1);
var arrTmp = strRight.split("&");
for(var i = 0; i < arrTmp.length; i++)
{
var arrTemp = arrTmp[i].split("=");
if(arrTemp[0].toUpperCase() == strName.toUpperCase())
return arrTemp[1];
}
return "";
}
</script>
</head>
<body style="margin:0;padding:0">
<div id="loading" style="position:absolute;width:100%;height:100%;left:0px;top:0px;background-color:#ffffff;filter:alpha(opacity=100)">
<div style="text-align:center;padding-top:200px">
载入中请稍候
.
<hr style="height:1px;width:50%" />
Loading
</div>
</div>
<iframe id="selectProvider" style="height:100%;width:100%;margin:0"></iframe>
</body>
<script language="javascript" type="text/javascript">
document.getElementById("selectProvider").src="StateChange.aspx?id="+Request("id");
</script>
</html>
最后效果还凑活着,和大家分享了。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述