.net网站建设页面提交后css失效的问题
问题描述:.net网站建设在提交后出现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"))
{
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>
问题解决:原因是,过去的提示语句我们一律使用了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"))
{
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>