用了下面一个方法,一点按钮整个页面就乱了,CSS完全不起作用!代码哪里错了?求高手帮忙改改!public static void Loading()
    {
        HttpContext hc = HttpContext.Current;
        hc.Response.Write("<div id='loading'> ");
        hc.Response.Write("<img src='loading.gif'/> ");
        hc.Response.Write("</div>");
        hc.Response.Write("<script type=text/javascript>");
        hc.Response.Write("function document.onreadystatechange()");
        hc.Response.Write(@"{ try  
                                   {
                                     if (document.readyState == 'complete') 
                                    {
                                          delNode('loading');
                                         
                                    }
                                    }
                                  catch(e)
                                     {
                                         alert('页面加载失败');
                                     }
                                                         }                             function delNode(nodeId)
                             {   
                                try
                                 {   
                                      var div =document.getElementById(nodeId); 
                                      if(div !==null)
                                       {
                                           div.parentNode.removeChild(div);   
                                          div=null;    
                                          CollectGarbage(); 
                                      } 
                                }
                                 catch(e)
                                 {   
                                   alert('ID为'+nodeId+'的节点出现异常');
                                 }   
                            }
 
                            ");        hc.Response.Write("</script>");
       hc.Response.Flush();c# asp.net loading 

解决方案 »

  1.   

    你都Response.Write了,这货完全破坏了原页面的DOM结构,页面不乱才怪了。
    要用ajax+json
      

  2.   

    不要在后台刷这些前台的js和css。Response.Write把代码在html的上面生成,你可以查看源文件看一下Html。
      

  3.   

    我觉得你这个完全可以再前台写jquery代码完成啊
    为什么要在后台去写呢
      

  4.   

    如楼1  完全不一样的HTML 结构啦.
      

  5.   

       生成的div跑到html外面去了,这就是原因吧!需要怎么改?求解答!!
      

  6.   

       生成的div跑到html外面去了,这就是原因吧!需要怎么改?求解答!!
    你可以搜索:jquery ajax 
    refer: http://www.w3school.com.cn/jquery/ajax_ajax.asp
    http://blog.csdn.net/smeyou/article/details/6218965
      

  7.   

       生成的div跑到html外面去了,这就是原因吧!需要怎么改?求解答!!用 ajax 或直接在前台js 方法里去render这些Dom对象
      

  8.   

    向1楼说的,最好还是用JS在前台构建HTML。
    如果你必须在后台代码中绘制HTML及JS,可以使用以下方法:后台添加JS:Page.ClientScript中提供的方法。
    后台绘制JS:
    重写Page的Render方法。