问题描述:在提交后出现css部分失效,如div位置,字体大小。
问题解决:原因是,过去的提示语句我们一律使用了Response.write("<script>alert("***")</script>"),用了.write输出 js脚本.
alert等破坏了css 加载。解决办法将Response.write("<script>alert("***")</script>")改换成 Page.RegisterStartupScript("Startup","<script>alert("***")</script>").
下面贴出msdn上的标准代码
<html>
<head>
<script language="C#" runat="server">
public void Page_Load(Object sender, EventArgs e)
{
if (!this.IsStartupScriptRegistered("Startup"))
{
// Form the script to be registered at client side.
String scriptString = "<script language=JavaScript> function DoClick() {";
scriptString += "showMessage2.innerHTML='<h4>Welcome to Microsoft .NET!</h4>'}";
scriptString += "function Page_Load(){ showMessage1.innerHTML=";
scriptString += "'<h4>RegisterStartupScript Example</h4>'}<";
scriptString += "/";
scriptString += "script>";
this.RegisterStartupScript("Startup", scriptString);
}
}
</script>
</head>
<body topmargin="20" leftmargin="10" onload="Page_Load()">
<form id="myForm" runat="server">
<span id="showMessage1"></span>
<br>
<input type="button" value="ClickMe" onclick="DoClick()">
<br>
<span id="showMessage2"></span>
</form>
</body>
</html>
<script language=JavaScript>
html自动弹出公告代码 function DoClick()
{
showMessage2.innerHTML='<h4>Welcome to Microsoft .NET!</h4>'
}
function Page_Load()
{
showMessage1.innerHTML='<h4>RegisterStartupScript Example</h4>'
}
</script>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论