一个项目,用asp.net4.0 C#在做,有用到ajax,
一个程序中,有要上传文件,因为ajax和FileUpload的冲突,找了很多资料,试了都不行,用Trigger设定都出错,
于是就放一个在UpdatePanel后面的层里面,用display控制显示和隐藏。在操作完成(写数据库和上传文件)后,Response.Write("<script>disDiv();</script>");让层隐藏,结果,页面的样式表不起作用,字体变大了。哪位兄弟有遇见过这种情况呀,怎么解决呀。附1:IE9 运行后的代码(PostBack后):<script>disDiv();</script><!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">
    function showDiv() {
        divAddMat.style.display = "";
    }
    function disDiv() {
        divAddMat.style.display = "none";
    }
</script>
    <style type="text/css">
        .style1
        {
            height: 25px;
        }
    </style><style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
font-size: 10pt;
}
-->
</style>
</head>
……附2:正常显示时的界面
附3:PostBack后的界面

解决方案 »

  1.   

    用Response.Write 页面不走样才怪
      

  2.   

    Response.Write("<script>disDiv();</script>");
    通过Response.Write方式像页面中写入脚本,会破坏页面的结构,导致字体变大换种方式实现即可
    ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>disDiv();</script>");
      

  3.   

    .net中使用Response.Write输出js会将js放在源代码的最前面,这样就可能出现破坏网页css的效果,让css失去效果   
    可以使用
    Page.ClientScript.RegisterStartupScript(this.GetType(), "", " <script language='javascript'>disDiv(); </script>");  
     
    可以解决页面变型或是css失效的问,但是代码会继续执行后面的程序。
      

  4.   

    回1楼,当然是因为变形才来问的呀。
    回2楼,谢谢了,问题解决了另:关于ajax和FileUpload冲突有什么好的解决方案吗?
      

  5.   


    随便搜了一个页面:http://slfileupload.codeplex.com/这类东西起码是开源的。而不是给控件做广告甚至卖盗版的。
      

  6.   


    <script>disDiv();</script><!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">
        function showDiv() {
            divAddMat.style.display = "";
        }
        function disDiv() {
            divAddMat.style.display = "none";
        }
    </script>
        <style type="text/css">
            .style1
            {
                height: 25px;
            }
        </style><style type="text/css">
    <!--
    body {
        margin-left: 0px;
        margin-top: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
        font-size: 10pt;
    }
    -->
    </style>
    </head>这个HTML破坏了html的文档结构
    所以样式出问题了改用
    ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>disDiv();</script>");
      

  7.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">、
    必须是第一行。不然就当非标准模式解析了。用 ClientScript.RegisterStartupScript 方法