<%@ 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
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
{
}
}