.net網站建設頁面提交後css失效的問題

y0umer發表於2013-08-05
問題描述:.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>

</html>

http://beijing.liebiao.com/wangzhanjianshe/46752756.html


相關文章