一个项目,用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后的界面
一个程序中,有要上传文件,因为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后的界面
通过Response.Write方式像页面中写入脚本,会破坏页面的结构,导致字体变大换种方式实现即可
ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>disDiv();</script>");
可以使用
Page.ClientScript.RegisterStartupScript(this.GetType(), "", " <script language='javascript'>disDiv(); </script>");
可以解决页面变型或是css失效的问,但是代码会继续执行后面的程序。
回2楼,谢谢了,问题解决了另:关于ajax和FileUpload冲突有什么好的解决方案吗?
随便搜了一个页面:http://slfileupload.codeplex.com/这类东西起码是开源的。而不是给控件做广告甚至卖盗版的。
<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>");
必须是第一行。不然就当非标准模式解析了。用 ClientScript.RegisterStartupScript 方法