<!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> <title></title> </head> <body> <form method="post" action="AddNumber.ashx"> <input type="hidden" name="ispostback" value="true" /> <input type="text" name="number1" value="@number1" /> + <input type="text" name="number2" value="@number2" /> <input type="submit" value="=" name="submit" /> <input type="text" name="result" value="@result"> </form> </body> </html>
<%@ WebHandler Language="C#" Class="AddNumber" %> using System; using System.Web; public class AddNumber : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/html"; //context.Response.Write("Hello World"); string ispostback = context.Request["ispostback"]; string number1 = context.Request["number1"]; string number2 = context.Request["number2"]; int result = 0; if (ispostback == "true") { result = Convert.ToInt32(number1) + Convert.ToInt32(number2); } else { result = 0; number1 = "0"; number2 = "0"; } string filepath = context.Server.MapPath("AddNumber.htm"); string content = System.IO.File.ReadAllText(filepath); content = content.Replace("@number1", number1); content = content.Replace("@number2", number2); content = content.Replace("@result", result.ToString()); context.Response.Write(content); } public bool IsReusable { get { return false; } } }