2012-06-28 49 views
0
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!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> 
    <link id="csslink" href="Handler.ashx" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <input id="Button1" type="button" value="Blue" /> 
     <input id="Button2" type="button" value="Red" /> 
    </div> 
    </form> 
    <script type="text/javascript"> 
     var pageDefault = { 
      btn1: document.getElementById('Button1'), 
      btn2: document.getElementById('Button2'), 
      csslink: document.getElementById('csslink'), 
      init: function() { 
       this.btn1.onclick = function() { 
        pageDefault.csslink.href = "Handler.ashx?id=1"; 
       } 
       this.btn2.onclick = function() { 
        pageDefault.csslink.href = "Handler.ashx?id=2"; 
       } 
      } 
     } 
     pageDefault.init(); 
    </script> 
</body> 
</html> 

,這裏將是該ASHX的ProcessRequest爲什麼在Firefox不會背景的變化,但它在IE

public void ProcessRequest(HttpContext context) 
    { 
     context.Response.ContentType = "text/plain"; 
     var id = context.Request.QueryString["id"]; 

     if (id == "1") 
     { 

      context.Response.Write(@" 
body 
{ 
    background: Blue; 
} 

"); 
     } 
     else if (id == "2") 
     { 
      context.Response.Write(@" 
body 
{ 
    background: Red; 
} 

"); 
     } 
     else 
     { 

     } 
    } 

回答

1
context.Response.ContentType = "text/css"; 
+0

謝謝你的眼睛!感謝所有的反饋 – Rod

0

嘗試使用:

body 
{ 
    /* Red */ 
    background-color: #ff0000; 
} 

body 
{ 
    /* Blue */ 
    background-color: #0c00ff; 
} 
+0

我改變了屬性背景顏色但仍然沒有運氣以及六角形顏色 – Rod

+0

這適用於我在Firefox中,所以它可能是一個代碼問題?你能顯示你的代碼生成的源代碼嗎? http://jsfiddle.net/REXZM/ – IrishChieftain

+0

酋長 - http://pastebin.com/buuGQVCb – Rod

相關問題