Ctrl+F5能成功应用CSS(居中,红色字体),但是点击Button1_Click()后CSS样式失效,但客户端test()正常.请问是怎么回事,如何解决.要能在服务端解决,而不是像本例中用javascript在客户端解决.谢谢!CSS:  ~/App_Themes/myskin/StyleSheet.css
#master_main{margin:0px auto; width:800px; color:Red; }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" Theme="myskin" %><!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 runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
    
      function test()
      {
         alert('客户端点击没问题~');
      }
    
    </script>
</head>
<body>
    <form id="form1" runat="server">
    
    <div id="master_main">  
        <table style="border-right: #000099 1px solid; border-top: #000099 1px solid; border-left: #000099 1px solid; border-bottom: #000099 1px solid">
            <tr>
                <td style="width: 100px">
                    1</td>
                <td style="width: 100px">
                    2</td>
                <td style="width: 100px">
                    3</td>
            </tr>  
        </table>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button"  OnClientClick="test()"/>
    </div>
    </form>
</body>
</html>[code=C#]using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>alert('为何点击后CSS无效了?')</script>");
    }
}
[/code]

解决方案 »

  1.   

    去掉
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    试试
      

  2.   

    Response.Write("<script>alert('为何点击后CSS无效了?')</script>");   的原因。
      

  3.   


    去掉后CSS就直接无效了~~~
      

  4.   

    很简单不要使用Response.Write()来输出页面脚本,建议使用:
    1.Literal,在页面中添加一个Literal控件,然后Literal1.Text="<script>alert('为何点击后CSS无效了?') </script>"); 
    2. Page.RegisterClientScriptBlock(""," <script>alert('为何点击后CSS无效了?') </script>");
    强烈建议使用第一种
      

  5.   

    Response.Write("<script>alert('为何点击后CSS无效了?')</script>");
     输出在页面代码最顶端了. 破坏了布局的CSS .
      

  6.   


     Response.Write("<script>alert('为何点击后CSS无效了?');window.location.href='aa.aspx'</script>");//假设你的当前页面为aa.aspx
      

  7.   

    不要用Response.Write来输出js语句,这样会破坏页面布局的,try:    protected void Button1_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(typeof(string),"js","alert('这样就不会无效了');",true);
        }
      

  8.   

    response,write()容易造成CSS失效
    用这个
    ClientScript.RegisterStartupScript()