我的页面加载可能要到1-2分钟,对于用户来说这是一个比较长的时间了。我想将页面做的友好一点,让用户知道系统正在加载页面,让用户耐心等待。所以想在页面加载好显示之前,先显示一个信息指示“正在生成您所需要的数据……”。可是不知道怎么实现。

解决方案 »

  1.   

     public static void initJavascript() 
        { 
            HttpContext.Current.Response.Write(" <script language=JavaScript type=text/javascript>"); 
            HttpContext.Current.Response.Write("var t_id = setInterval(animate,20);"); 
            HttpContext.Current.Response.Write("var pos=0;var dir=2;var len=0;"); 
            HttpContext.Current.Response.Write("function animate(){"); 
            HttpContext.Current.Response.Write("var elem = document.getElementById('progress');"); 
            HttpContext.Current.Response.Write("if(elem != null) {"); 
            HttpContext.Current.Response.Write("if (pos==0) len += dir;"); 
            HttpContext.Current.Response.Write("if (len>32 || pos>79) pos += dir;"); 
            HttpContext.Current.Response.Write("if (pos>79) len -= dir;"); 
            HttpContext.Current.Response.Write(" if (pos>79 && len==0) pos=0;"); 
            HttpContext.Current.Response.Write("elem.style.left = pos;"); 
            HttpContext.Current.Response.Write("elem.style.width = len;"); 
            HttpContext.Current.Response.Write("}}"); 
            HttpContext.Current.Response.Write("function remove_loading() {"); 
            HttpContext.Current.Response.Write(" this.clearInterval(t_id);"); 
            HttpContext.Current.Response.Write("var targelem = document.getElementById('loader_container');"); 
            HttpContext.Current.Response.Write("targelem.style.display='none';"); 
            HttpContext.Current.Response.Write("targelem.style.visibility='hidden';"); 
            HttpContext.Current.Response.Write("}"); 
            HttpContext.Current.Response.Write("</script>"); 
            HttpContext.Current.Response.Write("<style>"); 
            HttpContext.Current.Response.Write("#loader_container {text-align:center; position:absolute; top:40%; width:100%; left: 0;}"); 
            HttpContext.Current.Response.Write("#loader {font-family:Tahoma, Helvetica, sans; font-size:11.5px; color:#000000; background-color:#FFFFFF; padding:10px 0 16px 0; margin:0 auto; display:block; width:130px; border:1px solid #5a667b; text-align:left; z-index:2;}"); 
            HttpContext.Current.Response.Write("#progress {height:5px; font-size:1px; width:1px; position:relative; top:1px; left:0px; background-color:#8894a8;}"); 
            HttpContext.Current.Response.Write("#loader_bg {background-color:#e4e7eb; position:relative; top:8px; left:8px; height:7px; width:113px; font-size:1px;}"); 
            HttpContext.Current.Response.Write("</style>"); 
            HttpContext.Current.Response.Write("<div id=loader_container>"); 
            HttpContext.Current.Response.Write("<div id=loader>"); 
            HttpContext.Current.Response.Write("<div align=center>页面正在加载中 ...</div>"); 
            HttpContext.Current.Response.Write("<div id=loader_bg><div id=progress> </div></div>"); 
            HttpContext.Current.Response.Write("</div></div>"); 
            HttpContext.Current.Response.Flush(); 
        } 
    如果把这个方法放到页面中的话,不用引入其它命名空间,因为.aspx的页面已经把这个方法需要的命名空间引入了。 
    然后在Page_Load中,把这个方法引入。例:     
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack)//这很重要
          {
            initJavascript(); 
          }
      } 
    最后一点记住: 
    并在每个引用的页面body加载完毕后调用隐藏该div的事件 
    <body  onload="remove_loading();"> 
    这样就OK了!
      

  2.   

    其实用ajax是挺好实现的。。一加载的时刻我就这样去做。。
    $("document").ready(function(){$("#mydiv").htm("#mydiv").html("页面正在加载中。请等待");接着去去处理的数据显示。})
    在html中写上
    <div id="mydiv"></div>这样就要以了啊。如有不明白的话可以去我的博客看一下。那里我放了6篇这方面的文章的。。
      

  3.   

    不能用ajax,1楼的这种方式会使我的布局方式打乱